-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
70 lines (63 loc) · 1.89 KB
/
webpack.prod.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
const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const webpack = require('webpack')
const DATE = new Date()
const TIME = DATE.getTime()
const cssRule = {
resolve: { extensions: ['.scss', '.css'] },
test: /\.(sa|sc|c)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
}
const commonCacheGroup = {
chunks: 'initial',
minChunks: 2,
name: `chunk-common.${TIME}`,
priority: -30,
reuseExistingChunk: true
}
const vendorCacheGroup = {
chunks: 'all',
maxSize: 30000,
name: `common.${TIME}`,
test: /[\\/]node_modules[\\/]/
}
const output = {
chunkFilename: `js/${process.env.VERSION_APP}.[name].[id].${TIME}.[contenthash].[chunkhash].min.js`,
filename: `js/${process.env.VERSION_APP}.[name].${TIME}.[contenthash].min.js`,
path: path.resolve(__dirname, 'public'),
publicPath: '/'
}
const plugins = [
new webpack.ids.HashedModuleIdsPlugin({}),
new CompressionPlugin({
algorithm: 'gzip',
deleteOriginalAssets: true,
exclude: ['service-worker', 'firebase-messaging-sw', 'precache-manifest'],
filename: '[path][base].gz',
minRatio: Number.MAX_SAFE_INTEGER,
test: /\.js$|\.png$|\.svg$|\.css$|\.eot?.+$|\.ttf?.+$/,
threshold: 0
}),
new MiniCssExtractPlugin({
filename: `assets/css/${process.env.VERSION_APP}.[name].${TIME}.[contenthash].min.css`
})
]
module.exports = merge(common, {
devtool: false,
mode: 'production',
module: { rules: [cssRule] },
optimization: {
minimizer: [new CssMinimizerPlugin()],
runtimeChunk: 'single',
splitChunks: {
cacheGroups: { common: commonCacheGroup, vendor: vendorCacheGroup }
}
},
output,
plugins,
stats: 'minimal'
})