-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
87 lines (80 loc) · 2.06 KB
/
webpack.prod.js
File metadata and controls
87 lines (80 loc) · 2.06 KB
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
const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const MiniCssPlugin = require('mini-css-extract-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
const base = require('./webpack.base')
module.exports = merge(base, {
mode: 'production',
output: {
filename: '[name]-[contenthash].js',
chunkFilename: '[name]-[contenthash].chunk.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: [
MiniCssPlugin.loader,
'css-loader'
]
}
]
},
optimization: {
splitChunks: {
maxAsyncRequests: Infinity,
maxInitialRequests: Infinity,
cacheGroups: {
vendors: {
test: chunk => (
chunk.resource &&
/\.js$/.test(chunk.resource) &&
/node_modules/.test(chunk.resource)
),
chunks: 'initial',
name: 'vendors',
},
}
},
runtimeChunk: { name: 'runtime' }
},
plugins: [
new webpack.HashedModuleIdsPlugin(),
new webpack.NamedChunksPlugin(chunk => {
if (chunk.name) {
return chunk.name;
}
// eslint-disable-next-line no-underscore-dangle
return [...chunk._modules]
.map(m => path.relative(
m.context,
m.userRequest.substring(0, m.userRequest.lastIndexOf('.')),
))
.join('_');
}),
new MiniCssPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[name].[contenthash].css'
}),
new OptimizeCSSPlugin({}),
new ScriptExtHtmlWebpackPlugin({
inline: [
// https://github.com/webpack-contrib/mini-css-extract-plugin/issues/85
/styles.*\.js$/, // temporary fix style.js issue
/runtime/
],
prefetch: {
test: /\.js$/,
chunks: 'async',
},
preload: {
test: /\.js$/,
chunks: 'initial'
}
})
]
})