-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.prod.js
126 lines (117 loc) · 3.01 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const path = require('path');
const webpack = require('webpack');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const ManifestPlugin = require('webpack-manifest-plugin');
const ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const AfterEmitPlugin = require('./webpack-modules/after-emit-webpack-plugin');
const cssnano = require('cssnano');
const sassModule = require('./webpack-modules/sass-module');
const imgModule = require('./webpack-modules/img-module');
const jsPreModule = require('./webpack-modules/js-pre-module');
const jsModule = require('./webpack-modules/js-module');
const jsonModule = require('./webpack-modules/json-module');
const rules = [
sassModule,
imgModule,
jsPreModule,
jsModule,
jsonModule,
].map(module => module(true));
module.exports = {
entry: {
app: [
'./client/index.jsx',
],
vendor: [
'react',
'react-dom',
'react-redux',
'react-router',
'redux',
],
},
output: {
path: path.join(__dirname, 'client-dist'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[id].[chunkhash].js',
publicPath: '/',
},
resolve: {
extensions: ['*', '.js', '.jsx'],
modules: [
path.resolve('./client'),
path.resolve('./node_modules'),
],
},
module: {
rules,
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
browser: JSON.stringify(true),
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity,
filename: 'vendor.[chunkhash].js',
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
cssProcessor: cssnano,
cssProcessorOptions: {
discardComments: {
removeAll: true,
},
},
canPrint: true,
}),
new ExtractTextPlugin({
filename: 'app.[chunkhash].css',
allChunks: true,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false,
},
mangle: {
screw_ie8: true,
},
beautify: false,
comments: false,
}),
new ImageminPlugin({
test: /\.(jpe?g|gif|png|svg)$/i,
optipng: {
optimizationLevel: 3,
},
gifsicle: {
optimizationLevel: 1,
},
jpegtran: {
progressive: false,
},
svgo: {},
pngquant: null,
}),
new ManifestPlugin({
basePath: '/',
}),
new ChunkManifestPlugin({
filename: 'chunk-manifest.json',
manifestVariable: 'webpackManifest',
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '../bundle-report/bundle-report.html',
openAnalyzer: true,
}),
new AfterEmitPlugin(),
],
};