-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
155 lines (133 loc) · 3.39 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const { VueLoaderPlugin } = require('vue-loader');
const webpack = require('webpack');
module.exports = {
entry: {
'main': path.resolve(__dirname, 'src/index.js'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: (file) => {
return /node_modules/.test(file) && !/\.vue\.js/.test(file);
},
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.s[ac]ss$/i,
use: [
{
// Creates css file. Do not use together with style-loader
loader: MiniCssExtractPlugin.loader,
},
// Translates CSS into CommonJS
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
// resolve url() paths
loader: 'resolve-url-loader',
options: {
debug: true,
root: '/',
},
},
{
// Compiles Sass to CSS
loader: 'sass-loader',
options: {
sourceMap: true,
},
}
],
}
// {
// test: /\.(png|jpg|gif)$/,
// use: {
// loader: 'file-loader',
// options: {
// name: '[name].[ext]',
// outputPath: 'assets/img',
// },
// },
// },
// {
// // SVGs can be images or fonts
// test: /\.(svg)$/,
// use: {
// loader: 'file-loader',
// options: {
// name: '[name].[ext]',
// outputPath: (url, resourcePath, context) => {
// if (/\\fonts\\|\/fonts\//.test(resourcePath)) {
// return `assets/fonts/${url}`;
// }
// if (/\\icons\\|\/icons\/|\\img\\|\/img\//.test(resourcePath)) {
// console.log('Found an image or icon: ', url);
// return `assets/img/${url}`;
// }
// },
// },
// },
// },
// {
// test: /\.(eot|ttf|woff|woff2)$/,
// use: {
// loader: 'file-loader',
// options: {
// name: '[name].[ext]',
// outputPath: 'assets/fonts',
// },
// },
// }
],
},
resolve: {
alias: {
// String template workaround https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
'vue$': path.join(__dirname, 'node_modules/vue/dist/vue.esm-bundler.js'),
},
},
plugins: [
new CleanWebpackPlugin(),
new VueLoaderPlugin(),
new MiniCssExtractPlugin(
{
filename: '[name].css',
}
),
new CopyPlugin({
patterns: [
{
// "Flat" copies html files
from: 'src/**/*.html',
to: '[name][ext]',
}
],
}),
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
})
],
};