-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.prod.web.js
65 lines (60 loc) · 1.72 KB
/
webpack.prod.web.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
const { resolve } = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const ZipPlugin = require('zip-webpack-plugin');
const common = require('./webpack.common.js');
const config = require('./configs/config.dev');
const { title } = require('./package.json');
const version = '0.0.0';
const copyright = 'example name';
const setup = {
mode: 'production',
output: {
path: resolve(__dirname, './docs/demo'),
chunkFilename: 'phaser.js'
},
plugins: [
new CleanWebpackPlugin(['./docs/demo']),
new webpack.BannerPlugin({
banner: `${title} - ${version} © ${copyright}`
})
]
};
if (config.zip) {
setup.plugins.push(
new ZipPlugin({
filename: `${title}.${config.zipExtName}`
})
);
}
if (config.imageMin) {
setup.plugins.push(
new ImageminPlugin({
disable: process.env.NODE_ENV !== 'production',
test: /\.(jpe?g|png|gif|svg)$/i,
cacheFolder: resolve('./cache'),
optipng: {
optimizationLevel: config.imageMinQuality.png
},
gifsicle: {
optimizationLevel: config.imageMinQuality.gif
},
jpegtran: {
arithmetic: config.imageMinQuality.jpeg === 'arithmetic',
progressive: config.imageMinQuality.jpeg === 'progressive'
},
svgo: config.imageMinQuality.svg,
pngquant: config.imageMinQuality.pngquant
})
);
}
const configer = merge(common, setup);
webpack(configer, (err, stats) => {
if (err || stats.hasErrors()) {
// Handle errors here
console.log(stats.compilation.errors); // eslint-disable-line
}
// Done processing
});