-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprod-webpack-compiler.js
More file actions
43 lines (34 loc) · 1017 Bytes
/
prod-webpack-compiler.js
File metadata and controls
43 lines (34 loc) · 1017 Bytes
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
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const fse = require('fs-extra');
/* eslint-enable import/no-extraneous-dependencies */
const getConfig = require('./webpack.common.js');
const webpackConfig = getConfig();
webpackConfig.mode = 'production';
webpackConfig.output.publicPath = './';
const buildPath = webpackConfig.output.path;
if (buildPath !== __dirname) {
fse.removeSync(buildPath);
}
const compiler = webpack(webpackConfig);
webpackConfig.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false,
},
})
);
compiler.run((err, stats) => {
if (err) {
console.error('Webpack compiler encountered a fatal error.', err);
return;
}
console.info('Webpack compile completed.');
console.log(stats.toString({
chunks: false,
colors: true,
}));
console.info(`Webpack Compiler : Compilation duration -> ${stats.endTime - stats.startTime} ms.`);
});