1- var isDevBuild = process . argv . indexOf ( '--env.prod' ) < 0 ;
2- var path = require ( 'path' ) ;
3- var webpack = require ( 'webpack' ) ;
4- var AureliaWebpackPlugin = require ( 'aurelia-webpack-plugin' ) ;
1+ const path = require ( 'path' ) ;
2+ const webpack = require ( 'webpack' ) ;
3+ const { AureliaPlugin } = require ( 'aurelia-webpack-plugin' ) ;
54
6- var bundleOutputDir = './wwwroot/dist' ;
7- module . exports = {
8- resolve : { extensions : [ '.js' , '.ts' ] } ,
9- entry : { 'app' : 'aurelia-bootstrapper-webpack' } , // Note: The aurelia-webpack-plugin will add your app's modules to this bundle automatically
10- output : {
11- path : path . resolve ( bundleOutputDir ) ,
12- publicPath : '/dist' ,
13- filename : '[name].js'
14- } ,
15- module : {
16- loaders : [
17- { test : / \. t s $ / , include : / C l i e n t A p p / , loader : 'ts-loader' , query : { silent : true } } ,
18- { test : / \. h t m l $ / , loader : 'html-loader' } ,
19- { test : / \. c s s $ / , loaders : [ 'style-loader' , isDevBuild ? 'css-loader' : 'css-loader?minimize' ] } ,
20- { test : / \. ( p n g | w o f f | w o f f 2 | e o t | t t f | s v g ) $ / , loader : 'url-loader?limit=100000' } ,
21- { test : / \. j s o n $ / , loader : 'json-loader' }
5+ module . exports = ( { prod } = { } ) => {
6+ const isDevBuild = ! prod ;
7+ const isProdBuild = prod ;
8+ const bundleOutputDir = './wwwroot/dist' ;
9+
10+ return {
11+ resolve : {
12+ extensions : [ ".ts" , ".js" ] ,
13+ modules : [ "ClientApp" , "node_modules" ] ,
14+ } ,
15+ entry : { 'app' : 'aurelia-bootstrapper' } ,
16+ output : {
17+ path : path . resolve ( bundleOutputDir ) ,
18+ publicPath : "/dist/" ,
19+ filename : '[name].js'
20+ } ,
21+ module : {
22+ rules : [
23+ { test : / \. c s s $ / i, use : [ isDevBuild ? 'css-loader' : 'css-loader?minimize' ] } ,
24+ { test : / \. h t m l $ / i, use : [ "html-loader" ] } ,
25+ { test : / \. t s $ / i, loaders : [ 'ts-loader' ] , exclude : path . resolve ( __dirname , 'node_modules' ) } ,
26+ { test : / \. j s o n $ / i, loader : 'json-loader' , exclude : path . resolve ( __dirname , 'node_modules' ) } ,
27+ { test : / \. ( p n g | w o f f | w o f f 2 | e o t | t t f | s v g ) $ / , loader : 'url-loader' , query : { limit : 8192 } }
28+ ]
29+ } ,
30+ plugins : [
31+ new webpack . DefinePlugin ( { IS_DEV_BUILD : JSON . stringify ( isDevBuild ) } ) ,
32+ new webpack . DllReferencePlugin ( {
33+ context : __dirname ,
34+ manifest : require ( './wwwroot/dist/vendor-manifest.json' )
35+ } ) ,
36+ new AureliaPlugin ( { aureliaApp : "boot" } ) ,
37+ ...when ( isDevBuild , [
38+ new webpack . SourceMapDevToolPlugin ( {
39+ filename : '[file].map' ,
40+ moduleFilenameTemplate : path . relative ( bundleOutputDir , '[resourcePath]' )
41+ } )
42+ ] ) ,
43+ ...when ( isProdBuild , [
44+ new webpack . optimize . UglifyJsPlugin ( )
45+ ] )
2246 ]
23- } ,
24- plugins : [
25- new webpack . DefinePlugin ( { IS_DEV_BUILD : JSON . stringify ( isDevBuild ) } ) ,
26- new webpack . DllReferencePlugin ( {
27- context : __dirname ,
28- manifest : require ( './wwwroot/dist/vendor-manifest.json' )
29- } ) ,
30- new AureliaWebpackPlugin ( {
31- root : path . resolve ( './' ) ,
32- src : path . resolve ( './ClientApp' ) ,
33- baseUrl : '/'
34- } )
35- ] . concat ( isDevBuild ? [
36- // Plugins that apply in development builds only
37- new webpack . SourceMapDevToolPlugin ( {
38- filename : '[file].map' , // Remove this line if you prefer inline source maps
39- moduleFilenameTemplate : path . relative ( bundleOutputDir , '[resourcePath]' ) // Point sourcemap entries to the original file locations on disk
40- } )
41- ] : [
42- // Plugins that apply in production builds only
43- new webpack . optimize . UglifyJsPlugin ( )
44- ] )
45- } ;
47+ } ;
48+ }
49+
50+ const ensureArray = ( config ) => config && ( Array . isArray ( config ) ? config : [ config ] ) || [ ]
51+ const when = ( condition , config , negativeConfig ) => condition ? ensureArray ( config ) : ensureArray ( negativeConfig )
0 commit comments