webpack.prod.config.js
1.71 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
const merge = require('webpack-merge');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsParallelPlugin = require('webpack-uglify-parallel');
const os = require('os');
const pkg = require('../../package.json');
const path = require('path');
const distDir = path.join(__dirname, `../dist/${pkg.name}`);
let base = require('./webpack.base.config');
if (process.env.NODE_ENV === 'performance') {
const Visualizer = require('webpack-visualizer-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
base = merge(base, {
plugins: [
new Visualizer({
filename: '../../statistics.html'
}),
new BundleAnalyzerPlugin()
]
});
}
if (process.env.npm_config_report) {
let BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
base.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = merge(base, {
output: {
path: `${distDir}/${pkg.version}`
},
devtool: false,
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new UglifyJsParallelPlugin({
workers: os.cpus().length,
compress: {
warnings: false
},
comments: false
}),
new CopyWebpackPlugin([
{ from: './public/img', to: `${distDir}/${pkg.version}/img` },
{ from: './public/font', to: `${distDir}/${pkg.version}/font` }
], {
ignore: [
'sprite/**'
],
copyUnmodified: true
})
]
});