-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
executable file
·68 lines (63 loc) · 2.39 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
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const getProjectJsonPath = () => `${ process.env.PROJECT_CWD }/package.json`;
const VERSION = require(getProjectJsonPath()).version;
const FULLBUILD = new Date();
const distPath = path.join(process.env.PROJECT_CWD, './release/assets/js/min');
let baseConfig;
// check if we have a webpack.config in project root
try {
fs.accessSync(`${ process.env.PROJECT_CWD }/webpack.config.js`, fs.constants.R_OK | fs.constants.W_OK);
const getConfigPath = () => `${ process.env.PROJECT_CWD }/webpack.config.js`;
baseConfig = require(getConfigPath());
console.error('use webpack.base project config!');
} catch (err) {
const getConfigPath = () => `${ process.env.PWD }/webpack.config.js`;
baseConfig = require(getConfigPath());
console.error('use webpack.base package config!');
}
module.exports = merge(baseConfig, {
mode: 'production',
output: {
path: distPath,
chunkFilename: 'vhug-[name].min.bundle.js',
filename: 'vhug-[name].min.bundle.js'
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: false, // set to true if you want JS source maps on production
uglifyOptions: {
// mangle: false,
output: {
comments: /^\**!/
},
compress: {
drop_console: true,
unused: false
}
}
}),
]
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static'
}),
new webpack.BannerPlugin({
// print comments on top of each bundle file
banner: `Release version: ${JSON.stringify(VERSION)}, Build date: ${JSON.stringify(FULLBUILD)}, hash:[hash], chunkhash:[chunkhash], name:[name]`
}),
// don't create too small chunks here..
// if you only want one large chunk you can set this to higher values
new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 10000
})
],
});