11const webpack = require ( 'webpack' ) ;
22const path = require ( 'path' ) ;
3+ const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
34
4- module . exports = ( function ( options ) {
5+ module . exports = ( env => {
56
6- if ( ! options ) options = { isTest : false } ;
7+ if ( ! env ) env = { production : false } ;
78
8- var tsconfig = options . isTest ? "tsconfig.test.json" : "tsconfig.json" ;
9+ let tsconfig = env . production ? "tsconfig.json" : "tsconfig.test.json" ;
10+ let filename = env . production ? "signals.min.js" : "signals.js" ;
911
1012 return {
13+ mode : env . production ? "production" : "development" ,
1114 entry : {
1215 main : path . join ( __dirname , "src/index.ts" )
1316 } ,
1417
1518 output : {
1619 path : path . join ( __dirname , "dist" ) ,
17- filename : "signals.min.js" ,
20+ filename : filename ,
1821
1922 libraryTarget : "var" ,
2023 library : "SignalsJS"
2124 } ,
2225
23- devtool : ' inline-source-map' ,
26+ devtool : env . production ? undefined : " inline-source-map" ,
2427
2528 module : {
2629 rules : [
27- { test : / \. t s $ / , loader : "ts-loader?configFile=" + tsconfig } ,
2830 {
29- test : ( ( options . production ) /* disable this loader for production builds */
31+ test : / \. t s $ / ,
32+ loader : "ts-loader?configFile=" + tsconfig
33+ } ,
34+ {
35+ test : ( ( env . production ) /* disable this loader for production builds */
3036 ? / ^ $ /
3137 : / ^ ( .(? ! \. t e s t ) ) * \. t s $ / ) ,
3238 loader : "istanbul-instrumenter-loader" ,
@@ -39,8 +45,8 @@ module.exports = (function(options) {
3945 } ,
4046
4147 plugins : (
42- ( options . production )
43- ? [ new webpack . optimize . UglifyJsPlugin ( { sourceMap : false } ) ]
48+ ( env . production )
49+ ? [ new UglifyJSPlugin ( ) ]
4450 : [ new webpack . SourceMapDevToolPlugin ( { test : / \. t s $ / i } ) ]
4551 ) ,
4652
0 commit comments