-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.prod.js
91 lines (89 loc) · 2.86 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const webpackCommon = require('./webpack.common.js')
const merge = require('webpack-merge')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
// const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const { styleLoader } = require('./webpack.until.js')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const webpack = require('webpack')
const path = require('path')
const cfg = require('./webpack.cfg.js')
module.exports = (env, argv) => {
return merge(webpackCommon(env, argv), {
mode: 'production', // 当mode值为'production'时,webpack-dev-server 变动刷新反应很慢
devtool: cfg.build.productionSourceMap ? '#source-map' : undefined,
module: {
rules: [
{
test: /\.(css|scss|sass)$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: styleLoader,
publicPath:'../../'
})
},
]
},
plugins: [
new CleanWebpackPlugin('./dist'),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, cfg.build.assetsSubDirectory),
to: cfg.build.assetsSubDirectory,
ignore: ['.*']
}
]),
// new MiniCssExtractPlugin({
new ExtractTextPlugin({
filename: `${cfg.build.assetsSubDirectory}/css/[name].[md5:contenthash:hex:20].css`,
// filename: '[name].[md5:contenthash:hex:20].css', // 和html同目录是为了css相对路径起作用
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
}),
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false
}
},
sourceMap: cfg.build.productionSourceMap,
parallel: true
}),
new OptimizeCssAssetsPlugin({
cssProcessorOptions: {
// sourcemap: cfg.build.productionSourceMap,
map: cfg.build.productionSourceMap ? {
inline: false,
annotation: true
} : undefined,
autoprefixer: { disable: true },
cssProcessor: require('cssnano'),
cssProcessorOptions: { safe: true, discardComments: { removeAll: true } },
canPrint: true
}
}),
],
optimization: {
runtimeChunk: {
name: 'manifest',
},
splitChunks: {
minSize: 20000, // 超过20k才会被打包
cacheGroups: {
vendor: {
name: "vendor",
test: /[\\/]node_modules[\\/]/,
chunks: "all",
minChunks: 1
},
commons: {
name: "commons",
chunks: "all",
minChunks: 2
}
}
}
}
})
}