-
Notifications
You must be signed in to change notification settings - Fork 169
/
webpack.prod.config.js
62 lines (61 loc) · 1.92 KB
/
webpack.prod.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
const path = require('path');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const commonConfig = require('./webpack.common.config.js');
module.exports = merge(commonConfig, {
mode: 'production',
entry: {
app: ['babel-polyfill', path.resolve(__dirname, 'src/index.js')],
},
/* 输出到build文件夹,输出文件名字为[name].[chunkhash].js */
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'build'),
},
module: {
rules: [
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
plugins: [
new CleanWebpackPlugin(['build/*.*']),
new CompressionPlugin(),
new webpack.HashedModuleIdsPlugin(),
new MiniCssExtractPlugin({
ignoreOrder: true,
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
chunkFilename: '[id].css',
}),
new CopyWebpackPlugin([
{ from: 'src/manifest.json', to: 'manifest.json' },
{ from: 'src/service-worker.js', to: 'service-worker.js' },
]),
new ProgressBarPlugin(),
],
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
chunks: 'initial',
name: 'vendor',
enforce: true,
},
},
},
runtimeChunk: true,
},
});