@@ -4,21 +4,21 @@ import HtmlwebpackPlugin from 'html-webpack-plugin';
44import NpmInstallPlugin from 'npm-install-webpack-plugin' ;
55import Visualizer from 'webpack-visualizer-plugin' ;
66const ROOT_PATH = path . resolve ( __dirname ) ;
7-
87const env = process . env . NODE_ENV || 'development' ;
8+ const isProduction = env === 'production' ;
99const PORT = process . env . PORT || 1337 ;
1010const HOST = '0.0.0.0' ; // Set to localhost if need be.
1111
1212module . exports = {
13- devtool : process . env . NODE_ENV === 'production' ? '' : 'source-map' ,
13+ devtool : isProduction ? '' : 'source-map' ,
1414 entry : [
1515 path . resolve ( ROOT_PATH , 'app/src/index' )
1616 ] ,
1717 module : {
1818 preLoaders : [
1919 {
2020 test : / \. j s x ? $ / ,
21- loaders : process . env . NODE_ENV === 'production' ? [ ] : [ 'eslint' ] ,
21+ loaders : isProduction ? [ ] : [ 'eslint' ] ,
2222 include : path . resolve ( ROOT_PATH , './app' )
2323 }
2424 ] ,
@@ -76,7 +76,10 @@ module.exports = {
7676 } ,
7777 } ,
7878 output : {
79- path : process . env . NODE_ENV === 'production' ? path . resolve ( ROOT_PATH , 'server/public' ) : path . resolve ( ROOT_PATH , 'app/build' ) ,
79+ path : isProduction ?
80+ path . resolve ( ROOT_PATH , 'server/public' )
81+ :
82+ path . resolve ( ROOT_PATH , 'app/build' ) ,
8083 publicPath : '/' ,
8184 filename : 'bundle.js' ,
8285 } ,
@@ -91,13 +94,48 @@ module.exports = {
9194 host : HOST ,
9295 port : PORT
9396 } ,
94- plugins : [
95- new webpack . HotModuleReplacementPlugin ( ) ,
96- new NpmInstallPlugin ( ) ,
97- new HtmlwebpackPlugin ( {
98- title : 'Scalable React Boilerplate' ,
99- template : 'index.html'
100- } ) ,
101- new Visualizer ( )
102- ]
97+ plugins : process . env . NODE_ENV === 'production' ?
98+ [
99+ new ExtractTextPlugin ( '[name].[contenthash].css' ) ,
100+ new webpack . optimize . CommonsChunkPlugin ( {
101+ name : 'vendor' ,
102+ children : true ,
103+ minChunks : 2 ,
104+ async : true ,
105+ } ) ,
106+ new HtmlwebpackPlugin ( {
107+ template : 'config/templates/_index.html' ,
108+ minify : {
109+ removeComments : true ,
110+ collapseWhitespace : true ,
111+ removeRedundantAttributes : true ,
112+ useShortDoctype : true ,
113+ removeEmptyAttributes : true ,
114+ removeStyleLinkTypeAttributes : true ,
115+ keepClosingSlash : true ,
116+ minifyJS : true ,
117+ minifyCSS : true ,
118+ minifyURLs : true ,
119+ } ,
120+ inject : true ,
121+ } ) ,
122+ new webpack . DefinePlugin ( {
123+ 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV || 'development' )
124+ } ) ,
125+ new webpack . optimize . OccurrenceOrderPlugin ( true ) ,
126+ new webpack . optimize . DedupePlugin ( ) ,
127+ new webpack . optimize . UglifyJsPlugin ( {
128+ sourceMap : false
129+ } ) ,
130+ ]
131+ :
132+ [
133+ new webpack . HotModuleReplacementPlugin ( ) ,
134+ new NpmInstallPlugin ( ) ,
135+ new HtmlwebpackPlugin ( {
136+ title : 'Scalable React Boilerplate' ,
137+ template : 'index.html'
138+ } ) ,
139+ new Visualizer ( )
140+ ]
103141} ;
0 commit comments