-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (102 loc) · 3.09 KB
/
webpack.config.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
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = (env, argv) => ({
entry: {
app: './js/app.js',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'static')
},
module: {
rules: [
{
test: /\.vue$/,
exclude: /node_modules/,
loader: 'vue-loader',
options: {
compilerOptions: {
preserveWhitespace: false
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
},
{
test: /\.(woff|woff2|ttf|eot|png|svg)$/,
loader: "file-loader",
options: {
name: '[name].[ext]',
outputPath: 'assets'
}
},
]
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': argv.mode === 'production' ? 'vue/dist/vue.min.js' : 'vue/dist/vue.esm.js',
'buefy-style$': argv.mode === 'production' ? 'buefy/lib/buefy.min.css': 'buefy/lib/buefy.css',
}
},
optimization: {
minimizer: [
new UglifyJsPlugin({
parallel: true
}),
],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
minChunks: 2 // shared between two entry at least
}
}
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: argv.mode === 'production' ? '"production"' : '"development"'
}
}),
new BundleAnalyzerPlugin({
analyzerMode: argv.mode === 'production' ? 'disabled' : 'server',
openAnalyzer: false
}),
new CompressionPlugin({
test: /\.(js)/,
algorithm: 'gzip',
minRatio: 0.8,
asset: '[path].gz[query]'
}),
new MiniCssExtractPlugin({
chunkFilename: "style.css",
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: argv.mode === 'production' ? /\.css$/g : /\$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: {
discardComments: {removeAll: true}
},
})
]
})
;