@@ -15,19 +15,8 @@ module.exports = function makeWebpackConfig(options) {
1515 var BUILD = ! ! options . BUILD ;
1616 var TEST = ! ! options . TEST ;
1717
18- /**
19- * Config
20- * Reference: http://webpack.github.io/docs/configuration.html
21- * This is the object where all configuration gets set
22- */
2318 var config = { } ;
2419
25- /**
26- * Entry
27- * Reference: http://webpack.github.io/docs/configuration.html#entry
28- * Should be an empty object if it's generating a test build
29- * Karma will set this when it's a test build
30- */
3120 if ( TEST ) {
3221 config . entry = { }
3322 } else {
@@ -36,40 +25,23 @@ module.exports = function makeWebpackConfig(options) {
3625 }
3726 }
3827
39- /**
40- * Output
41- * Reference: http://webpack.github.io/docs/configuration.html#output
42- * Should be an empty object if it's generating a test build
43- * Karma will handle setting it up for you when it's a test build
44- */
4528 if ( TEST ) {
4629 config . output = { }
4730 } else {
4831 config . output = {
4932 // Absolute output directory
5033 path : __dirname + '/public' ,
5134
52- // Output path from the view of the page
53- // Uses webpack-dev-server in development
5435 publicPath : BUILD ? '/' : 'http://localhost:8080/' ,
5536
56- // Filename for entry points
57- // Only adds hash in build mode
5837 filename : BUILD ? '[name].[hash].js' : '[name].bundle.js' ,
5938 //filename: 'bundle.js',
6039
61- // Filename for non-entry points
62- // Only adds hash in build mode
6340 chunkFilename : BUILD ? '[name].[hash].js' : '[name].bundle.js'
6441 //chunkFilename: BUILD ? 'bundle.js' : 'bundle.js'
6542 }
6643 }
6744
68- /**
69- * Devtool
70- * Reference: http://webpack.github.io/docs/configuration.html#devtool
71- * Type of sourcemap to use per build type
72- */
7345 if ( TEST ) {
7446 config . devtool = 'inline-source-map' ;
7547 } else if ( BUILD ) {
@@ -78,46 +50,21 @@ module.exports = function makeWebpackConfig(options) {
7850 config . devtool = 'eval' ;
7951 }
8052
81- /**
82- * Loaders
83- * Reference: http://webpack.github.io/docs/configuration.html#module-loaders
84- * List: http://webpack.github.io/docs/list-of-loaders.html
85- * This handles most of the magic responsible for converting modules
86- */
87-
88- // Initialize module
8953 config . module = {
9054 preLoaders : [ ] ,
9155 loaders : [ {
92- // JS LOADER
93- // Reference: https://github.com/babel/babel-loader
94- // Transpile .js files using babel-loader
95- // Compiles ES6 and ES7 into ES5 code
9656 test : / \. j s $ / ,
9757 loader : 'babel' ,
9858 exclude : / n o d e _ m o d u l e s /
9959 } , {
100- // ASSET LOADER
101- // Reference: https://github.com/webpack/file-loader
102- // Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output
103- // Rename the file using the asset hash
104- // Pass along the updated reference to your code
105- // You can add here any file extension you want to get copied to your output
10660 test : / \. ( p n g | j p g | j p e g | g i f | s v g | w o f f | w o f f 2 | t t f | e o t ) $ / ,
10761 loader : 'file'
10862 } , {
109- // HTML LOADER
110- // Reference: https://github.com/webpack/raw-loader
111- // Allow loading html through js
11263 test : / \. h t m l $ / ,
11364 loader : 'raw'
11465 } ]
11566 } ;
11667
117- // ISPARTA LOADER
118- // Reference: https://github.com/ColCh/isparta-instrumenter-loader
119- // Instrument JS files with Isparta for subsequent code coverage reporting
120- // Skips node_modules and files that end with .test.js
12168 if ( TEST ) {
12269 config . module . preLoaders . push ( {
12370 test : / \. j s $ / ,
@@ -131,52 +78,24 @@ module.exports = function makeWebpackConfig(options) {
13178 } ) ;
13279 }
13380
134- // CSS LOADER
135- // Reference: https://github.com/webpack/css-loader
136- // Allow loading css through js
137- //
138- // Reference: https://github.com/postcss/postcss-loader
139- // Postprocess your css with PostCSS plugins
14081 var cssLoader = {
14182 test : / \. c s s $ / ,
142- // Reference: https://github.com/webpack/extract-text-webpack-plugin
143- // Extract css files in production builds
144- //
145- // Reference: https://github.com/webpack/style-loader
146- // Use style-loader in development for hot-loading
14783 loader : ExtractTextPlugin . extract ( 'style' , 'css?sourceMap!postcss' )
14884 } ;
14985
150- // Skip loading css in test mode
15186 if ( TEST ) {
152- // Reference: https://github.com/webpack/null-loader
153- // Return an empty module
15487 cssLoader . loader = 'null' ;
15588 }
15689
157- // Add cssLoader to the loader list
15890 config . module . loaders . push ( cssLoader ) ;
15991
160- /**
161- * PostCSS
162- * Reference: https://github.com/postcss/autoprefixer-core
163- * Add vendor prefixes to your css
164- */
16592 config . postcss = [
16693 autoprefixer ( {
16794 browsers : [ 'last 2 version' ]
16895 } )
16996 ] ;
17097
171- /**
172- * Plugins
173- * Reference: http://webpack.github.io/docs/configuration.html#plugins
174- * List: http://webpack.github.io/docs/list-of-plugins.html
175- */
17698 config . plugins = [
177- // Reference: https://github.com/webpack/extract-text-webpack-plugin
178- // Extract css files
179- // Disabled when in test mode or not in build mode
18099 new ExtractTextPlugin ( '[name].[hash].css' , {
181100 disable : ! BUILD || TEST
182101 } ) ,
@@ -189,10 +108,7 @@ module.exports = function makeWebpackConfig(options) {
189108 } )
190109 ] ;
191110
192- // Skip rendering index.html in test mode
193111 if ( ! TEST ) {
194- // Reference: https://github.com/ampedandwired/html-webpack-plugin
195- // Render index.html
196112 config . plugins . push (
197113 new HtmlWebpackPlugin ( {
198114 template : './public/index.html' ,
@@ -201,19 +117,10 @@ module.exports = function makeWebpackConfig(options) {
201117 )
202118 }
203119
204- // Add build specific plugins
205120 if ( BUILD ) {
206121 config . plugins . push (
207- // Reference: http://webpack.github.io/docs/list-of-plugins.html#noerrorsplugin
208- // Only emit files when there are no errors
209122 new webpack . NoErrorsPlugin ( ) ,
210-
211- // Reference: http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
212- // Dedupe modules in the output
213123 new webpack . optimize . DedupePlugin ( ) ,
214-
215- // Reference: http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
216- // Minify all javascript, switch loaders to minimizing mode
217124 new webpack . optimize . UglifyJsPlugin ( )
218125 ) ;
219126 }
0 commit comments