-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.prod.js
89 lines (87 loc) · 2.45 KB
/
webpack.config.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
// const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { merge } = require('webpack-merge');
const base = require('./webpack.config');
const prod = {
mode: 'production',
entry: {
app: [path.resolve('src', 'index.js')],
vendor: [
'react',
'react-dom',
'react-router-dom',
'axios',
'moment',
'immutable',
'react-redux',
'redux',
'redux-actions',
'redux-immutable',
'react-simplemde-editor',
],
},
output: {
path: path.resolve('dist'),
publicPath: '/',
filename: 'static/js/[name].[chunkhash:8].js',
chunkFilename: 'static/js/[name].[chunkhash:8].min.js',
},
optimization: {
minimize: true,
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
name: 'vendor',
test: 'vendor',
enforce: true,
},
},
},
runtimeChunk: {
name: (entrypoint) => `runtime-${entrypoint.name}`,
},
},
plugins: [
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn/),
new HtmlWebpackPlugin({
template: 'public/index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new WebpackManifestPlugin({
fileName: 'asset-manifest.json',
}),
// new SWPrecacheWebpackPlugin({
// dontCacheBustUrlsMatching: /\.\w{8}\./,
// filename: 'service-worker.js',
// minify: true,
// navigateFallback: '/index.html',
// navigateFallbackWhitelist: [/^(?!\/__).*/],
// staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
// }),
new CleanWebpackPlugin({
verbose: true,
}),
// new BundleAnalyzerPlugin(),
],
};
module.exports = merge(base, prod);