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 , karma : false } ;
78
8- var tsconfig = options . isTest ? "tsconfig.test.json" : "tsconfig.json" ;
9+ let mode = env . production ? "production" : "development" ;
10+ let tsconfig = ! env . karma ? "tsconfig.json" : "tsconfig.test.json" ;
11+ let output = env . production ? "dist" : "dev" ;
12+ let filename = env . production ? "robotlegs-phaser-signalcommandmap.min.js" : "robotlegs-phaser-signalcommandmap.js" ;
913
1014 return {
15+ mode : mode ,
1116 entry : {
1217 main : path . join ( __dirname , "src/index.ts" )
1318 } ,
1419
1520 output : {
16- path : path . join ( __dirname , "dist" ) ,
17- filename : "bundle.js"
21+ path : path . join ( __dirname , output ) ,
22+ filename : filename ,
23+
24+ libraryTarget : "var" ,
25+ library : "RobotlegsJSPhaserSignalCommandMap"
1826 } ,
1927
20- devtool : ' inline-source-map' ,
28+ devtool : env . production ? undefined : " inline-source-map" ,
2129
2230 module : {
2331 rules : [
24- { test : / \. t s $ / , loader : "ts-loader?configFile=" + tsconfig } ,
2532 {
26- test : / ^ ( .(? ! \. t e s t ) ) * \. t s $ / ,
33+ test : / \. t s $ / ,
34+ loader : "ts-loader?configFile=" + tsconfig
35+ } ,
36+ {
37+ test : ( ( env . production ) /* disable this loader for production builds */
38+ ? / ^ $ /
39+ : / ^ ( .(? ! \. t e s t ) ) * \. t s $ / ) ,
2740 loader : "istanbul-instrumenter-loader" ,
2841 query : {
2942 embedSource : true
@@ -33,16 +46,14 @@ module.exports = (function(options) {
3346 ]
3447 } ,
3548
36- plugins : [
37- // new webpack.optimize.UglifyJsPlugin()
38- new webpack . SourceMapDevToolPlugin ( { test : / \. t s $ / i } )
39- ] ,
49+ plugins : (
50+ ( env . production )
51+ ? [ new UglifyJSPlugin ( ) ]
52+ : [ new webpack . SourceMapDevToolPlugin ( { test : / \. t s $ / i } ) ]
53+ ) ,
4054
4155 resolve : {
42- extensions : [ '.ts' , '.js' , '.json' ] ,
43- alias : {
44- // sinon: 'sinon/pkg/sinon'
45- }
56+ extensions : [ '.ts' , '.js' , '.json' ]
4657 }
4758 }
48- } ) ;
59+ } ;
0 commit comments