1+ 'use strict' ; // eslint-disable-line
2+
13const webpack = require ( 'webpack' ) ;
24const qs = require ( 'qs' ) ;
35const autoprefixer = require ( 'autoprefixer' ) ;
46const CleanPlugin = require ( 'clean-webpack-plugin' ) ;
57const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
6- const ImageminPlugin = require ( 'imagemin-webpack-plugin' ) . default ;
7- const imageminMozjpeg = require ( 'imagemin-mozjpeg' ) ;
88
99const CopyGlobsPlugin = require ( './webpack.plugin.copyglobs' ) ;
1010const mergeWithConcat = require ( './util/mergeWithConcat' ) ;
11- const addHotMiddleware = require ( './util/addHotMiddleware' ) ;
12- const webpackConfigProduction = require ( './webpack.config.production' ) ;
13- const webpackConfigWatch = require ( './webpack.config.watch' ) ;
1411const config = require ( './config' ) ;
1512
1613const assetsFilenames = ( config . enabled . cacheBusting ) ? config . cacheBusting : '[name]' ;
@@ -29,7 +26,7 @@ if (config.enabled.watcher) {
2926 jsLoader . loaders . unshift ( 'monkey-hot?sourceType=module' ) ;
3027}
3128
32- const webpackConfig = {
29+ let webpackConfig = {
3330 context : config . paths . assets ,
3431 entry : config . entry ,
3532 devtool : ( config . enabled . sourceMaps ? '#source-map' : undefined ) ,
@@ -118,22 +115,17 @@ const webpackConfig = {
118115 jquery : 'jQuery' ,
119116 } ,
120117 plugins : [
121- new CleanPlugin ( [ config . paths . dist ] , config . paths . root ) ,
118+ new CleanPlugin ( [ config . paths . dist ] , {
119+ root : config . paths . root ,
120+ verbose : false ,
121+ } ) ,
122122 new CopyGlobsPlugin ( {
123123 // It would be nice to switch to copy-webpack-plugin, but unfortunately it doesn't
124124 // provide a reliable way of tracking the before/after file names
125125 pattern : config . copy ,
126126 output : `[path]${ assetsFilenames } .[ext]` ,
127127 manifest : config . manifest ,
128128 } ) ,
129- new ImageminPlugin ( {
130- optipng : { optimizationLevel : 7 } ,
131- gifsicle : { optimizationLevel : 3 } ,
132- pngquant : { quality : '65-90' , speed : 4 } ,
133- svgo : { removeUnknownsAndDefaults : false , cleanupIDs : false } ,
134- plugins : [ imageminMozjpeg ( { quality : 75 } ) ] ,
135- disable : ( config . enabled . watcher ) ,
136- } ) ,
137129 new ExtractTextPlugin ( {
138130 filename : `styles/${ assetsFilenames } .css` ,
139131 allChunks : true ,
@@ -152,7 +144,7 @@ const webpackConfig = {
152144 : false ,
153145 } ) ,
154146 new webpack . LoaderOptionsPlugin ( {
155- minimize : config . enabled . minify ,
147+ minimize : config . enabled . optimize ,
156148 debug : config . enabled . watcher ,
157149 stats : { colors : true } ,
158150 } ) ,
@@ -175,21 +167,33 @@ const webpackConfig = {
175167 ] ,
176168} ;
177169
178- module . exports = webpackConfig ;
170+ /* eslint-disable global-require */ /** Let's only load dependencies as needed */
179171
180- if ( config . env . production ) {
181- module . exports = mergeWithConcat ( webpackConfig , webpackConfigProduction ) ;
172+ if ( config . env . optimize ) {
173+ webpackConfig = mergeWithConcat ( webpackConfig , require ( './webpack.config.optimize' ) ) ;
182174}
183175
184- if ( config . enabled . watcher ) {
185- module . exports . entry = addHotMiddleware ( webpackConfig . entry ) ;
186- module . exports = mergeWithConcat ( webpackConfig , webpackConfigWatch ) ;
176+ if ( config . env . production ) {
177+ webpackConfig . plugins . push ( new webpack . NoErrorsPlugin ( ) ) ;
187178}
188179
189- if ( config . enabled . uglifyJs ) {
190- module . exports . plugins . push (
191- new webpack . optimize . UglifyJsPlugin ( {
192- sourceMap : config . enabled . sourceMaps ,
180+ if ( config . enabled . cacheBusting ) {
181+ const WebpackAssetsManifest = require ( 'webpack-assets-manifest' ) ;
182+
183+ webpackConfig . plugins . push (
184+ new WebpackAssetsManifest ( {
185+ output : 'assets.json' ,
186+ space : 2 ,
187+ writeToDisk : false ,
188+ assets : config . manifest ,
189+ replacer : require ( './util/assetManifestsFormatter' ) ,
193190 } )
194191 ) ;
195192}
193+
194+ if ( config . enabled . watcher ) {
195+ webpackConfig . entry = require ( './util/addHotMiddleware' ) ( webpackConfig . entry ) ;
196+ webpackConfig = mergeWithConcat ( webpackConfig , require ( './webpack.config.watch' ) ) ;
197+ }
198+
199+ module . exports = webpackConfig ;
0 commit comments