-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.prod.plugin.js
89 lines (80 loc) · 2.33 KB
/
webpack.prod.plugin.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
const path = require('path');
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 UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
const common = require('./webpack.common.js');
const config = require('./configs/config.dev');
const name = 'sample';
const version = '0.0.0';
const copyright = 'example name';
const zip = true;
const setup = {
mode: 'production',
output: {
chunkFilename: 'phaser.js'
},
plugins: [new CleanWebpackPlugin([`build/plugins/${name}`]), new UnminifiedWebpackPlugin()]
};
common.entry = {
[`${name}`]: `./plugins/${name}`
};
common.output = {
path: path.resolve(__dirname, `./build/plugins/${name}`),
filename: '[name].min.js',
library: name,
libraryTarget: 'umd',
umdNamedDefine: true
};
common.plugins = [
new webpack.DefinePlugin({
// Enable both canvas and WebGL for better support
'typeof CANVAS_RENDERER': JSON.stringify(true),
'typeof WEBGL_RENDERER': JSON.stringify(true),
// Development env
_DEV_: JSON.stringify(true),
_VERSION_: JSON.stringify(version)
}),
new webpack.BannerPlugin({
banner: `${name} - ${version} © ${copyright}`
})
];
if (config.zip && zip) {
setup.plugins.push(
new ZipPlugin({
filename: `${name}.${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
});