forked from shanewilson/react-webpack-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.config.js
69 lines (62 loc) · 1.55 KB
/
webpack.prod.config.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
'use strict';
var minify = require('html-minifier').minify;
var webpack = require('webpack');
var CompressionPlugin = require('compression-webpack-plugin');
var config = require('./webpack.base.config.js');
config.bail = true;
config.debug = false;
config.profile = false;
config.devtool = '#source-map';
config.output = {
path: './dist/js',
pathInfo: false,
publicPath: '/js/',
filename: '[name].[hash].min.js',
css: 'style.[hash].min.css',
chunkFilename: '[id].js'
};
config.postcss = [
// Optimizations
require('postcss-import'),
require('csswring'),
require('postcss-discard-duplicates')(),
require('postcss-calc')()
].concat(config.postcss);
config.plugins = config.plugins.concat([
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['require', 'export', '$super']
},
compress: {
warnings: false,
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
}
}),
new CompressionPlugin({
asset: '{file}.gz',
algorithm: 'gzip',
regExp: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]);
config.revFiles = function(data, files) {
files.forEach(function(file) {
var path = file.name.split('.');
data = data.replace(path[0] + '.' + path[path.length - 1], file.name);
});
return minify(data, {
collapseWhitespace: true,
removeAttributeQuotes: true,
useShortDoctype: true
});
};
module.exports = config;