-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.production-builder.js
68 lines (64 loc) · 2.51 KB
/
webpack.production-builder.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
process.env.BROWSERSLIST_CONFIG = process.env.BROWSERSLIST_CONFIG || require.resolve('./.browserslistrc');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
function webpackProductionConfigBuilder(options) {
options = options || {};
const extractMainCSS = new ExtractTextPlugin(options.extractMainCSS || '[name].[hash].css');
const extractIconsCSS = new ExtractTextPlugin(options.extractIconsCSS || '[name]-icons.[hash].css');
const extractOptions = Object.assign({
fallback: require.resolve('style-loader'),
use: [require.resolve('css-loader'), require.resolve('postcss-loader')]
}, options.extractOptions);
return {
module: {
rules: [
{
test: /\.css$/,
exclude: /icon.*\.css$/,
use: extractMainCSS.extract(extractOptions)
},
{
test: /icon.*\.css$/,
use: extractIconsCSS.extract(extractOptions)
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks(module) {
return module.userRequest
&& (module.userRequest.indexOf('arui') === -1 || module.userRequest.indexOf('polyfills') !== -1)
&& module.userRequest.indexOf('node_modules') !== -1;
}
}),
new ManifestPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
sourceMap: false,
warnings: false
}),
extractMainCSS,
extractIconsCSS,
new OptimizeCssAssetsPlugin({
cssProcessorOptions: {
reduceIdents: {
keyframes: false
}
}
}),
new CompressionPlugin({
asset: '[file].gz',
algorithm: 'gzip',
regExp: /\.js$|\.css$|\.png$|\.svg$/,
threshold: 10240,
minRatio: 0.8
})
]
};
}
module.exports = webpackProductionConfigBuilder;