-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.prod.js
81 lines (67 loc) · 1.97 KB
/
webpack.config.prod.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
'use strict';
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const StatsWriterPlugin = require('./src/libs/webpack-perfomance-budget/plugin');
if (typeof process.env.NODE_ENV === 'undefined') {
process.env.NODE_ENV = 'production';
}
if (!module.parent || module.parent.id.indexOf('node_modules') > -1) {
const config = require(`${__dirname}/webpack.config`);
module.exports = transform(config);
}
module.exports.transform = transform;
function getVendors() {
return [
'core-js',
'engine.io-client',
'history',
'json3',
'lodash',
'moment',
'react',
'react-autosuggest',
'react-dom',
'react-portal-tooltip',
'react-router',
'redux',
'regenerator-runtime',
'socket.io-client',
'tcomb'
];
}
function transform(config) {
config.entry.vendors = getVendors();
config.devtool = 'source-map';
config.output.filename = '[name].bundle.[chunkhash].js';
const prodPlugins = config.plugins.reduce((total, curr) => {
if (!(curr instanceof webpack.HotModuleReplacementPlugin)) {
total.push(curr);
}
return total;
}, [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.bundle.[chunkhash].js'),
new ExtractTextPlugin('styles.css', '[name].[contenthash].css')
]).concat([
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
new StatsWriterPlugin({
filename: 'stats.json'
})
]);
config.plugins = prodPlugins;
const prodLoaders = config.module.loaders.reduce((total, curr) => {
if (curr.loader && curr.loader.indexOf('style-loader') > -1) {
const data = curr.loader.split('!');
curr.loader = ExtractTextPlugin.extract('style-loader', data.slice(1).join('!'));
}
total.push(curr);
return total;
}, []);
config.module.loaders = prodLoaders;
return config;
}