@@ -77,6 +77,7 @@ export class Kaba
77
77
h : [ "preact" , "h" ] ,
78
78
Fragment : [ "preact" , "Fragment" ] ,
79
79
} ) ,
80
+ new CleanWebpackPlugin ( ) ,
80
81
] ;
81
82
82
83
// set defaults
@@ -277,20 +278,16 @@ export class Kaba
277
278
const compilerConfigs : kaba . WebpackBuildConfig [ ] = [ ] ;
278
279
279
280
Object . keys ( this . jsEntries ) . forEach ( ( entry : string ) => {
281
+ compilerConfigs . push ( this . buildWebpackConfig ( entry , this . jsEntries [ entry ] , cliConfig , false ) ) ;
282
+
280
283
if ( this . buildModern )
281
284
{
282
285
compilerConfigs . push ( this . buildWebpackConfig ( entry , this . jsEntries [ entry ] , cliConfig , true ) ) ;
283
286
}
284
287
} ) ;
285
288
286
- // The log output gets really big with multiple entry files.
287
- // Therefore the linted (legacy) entries are added after the modern ones.
288
- Object . keys ( this . jsEntries ) . forEach ( ( entry : string ) => {
289
- compilerConfigs . push ( this . buildWebpackConfig ( entry , this . jsEntries [ entry ] , cliConfig , false ) ) ;
290
- } ) ;
291
-
292
289
jsConfig = {
293
- common : this . buildWebpackCommon ( cliConfig ) ,
290
+ watch : cliConfig . watch ,
294
291
configs : compilerConfigs ,
295
292
javaScriptDependenciesFileName : this . javaScriptDependenciesFileName ,
296
293
basePath : path . join ( this . outputPaths . base , this . outputPaths . js ) ,
@@ -311,11 +308,34 @@ export class Kaba
311
308
312
309
313
310
/**
314
- * Builds the common webpack config, that is common between legacy & module
311
+ * Builds the specialized webpack config for a legacy / module build
315
312
*/
316
- private buildWebpackCommon ( cliConfig : kaba . CliConfig ) : Partial < webpack . Configuration >
313
+ private buildWebpackConfig ( entry : string , entryFile : string , cliConfig : kaba . CliConfig , isModule : boolean ) : Partial < webpack . Configuration >
317
314
{
318
- const config : Partial < webpack . Configuration > = {
315
+ const babelLoader = {
316
+ loader : "babel-loader?cacheDirectory" ,
317
+ options : {
318
+ babelrc : false ,
319
+ presets : [
320
+ [ isModule ? kabaBabelPreset . modern : kabaBabelPreset . legacy ] ,
321
+ ] ,
322
+ } ,
323
+ } ;
324
+
325
+ let typeScriptConfig = path . join (
326
+ this . libRoot ,
327
+ "configs" ,
328
+ isModule ? "tsconfig.modern.json" : "tsconfig.legacy.json" ,
329
+ ) ;
330
+
331
+ const entryName = isModule ? `_modern.${ entry } ` : entry ;
332
+
333
+ let configTemplate = {
334
+ name : isModule ? "modern" : "legacy" ,
335
+ entry : {
336
+ [ entryName ] : entryFile ,
337
+ } ,
338
+
319
339
// mode
320
340
mode : cliConfig . debug ? "development" : "production" ,
321
341
@@ -340,9 +360,47 @@ export class Kaba
340
360
] ,
341
361
} ,
342
362
363
+ // output
364
+ output : {
365
+ path : path . join ( this . outputPaths . base , this . outputPaths . js , isModule ? "modern" : "legacy" ) ,
366
+ filename : this . hashFileNames ? '[name].[chunkhash].js' : '[name].js' ,
367
+ // the slash at the end is required of the public path entries
368
+ publicPath : path . join ( this . publicPath , isModule ? "modern/" : "legacy/" ) ,
369
+ pathinfo : cliConfig . debug ,
370
+ } ,
371
+
343
372
// module
344
373
module : {
345
- rules : [ ] ,
374
+ rules : [
375
+ // TypeScript
376
+ {
377
+ test : / \. t s x ? $ / ,
378
+ use : [
379
+ 'cache-loader' ,
380
+ babelLoader ,
381
+ {
382
+ loader : "ts-loader" ,
383
+ options : {
384
+ context : this . cwd ,
385
+ configFile : typeScriptConfig ,
386
+ errorFormatter : ( message , colors ) => typeScriptErrorFormatter ( message , colors , this . cwd ) ,
387
+ } ,
388
+ } ,
389
+ ] ,
390
+ } ,
391
+
392
+ // Babel
393
+ {
394
+ test : / \. m ? j s x ? $ / ,
395
+ use : [ 'cache-loader' , babelLoader ] ,
396
+ } ,
397
+
398
+ // content files
399
+ {
400
+ test : / \. ( s v g | t x t ) $ / ,
401
+ loader : "raw-loader" ,
402
+ } ,
403
+ ] as webpack . RuleSetRule [ ] ,
346
404
} ,
347
405
348
406
// optimization
@@ -351,8 +409,6 @@ export class Kaba
351
409
minimizer : [ ] ,
352
410
} ,
353
411
354
- // performance
355
-
356
412
// devtool (source maps)
357
413
devtool : cliConfig . debug
358
414
? "inline-cheap-source-map"
@@ -373,10 +429,11 @@ export class Kaba
373
429
stats : {
374
430
// hide children information (like from the ExtractTextPlugin)
375
431
children : false ,
432
+ hash : ! isModule ,
433
+ version : ! isModule ,
434
+ modules : ! isModule ,
376
435
} ,
377
436
378
- // devServer
379
-
380
437
// plugins
381
438
plugins : this . plugins ,
382
439
@@ -387,11 +444,20 @@ export class Kaba
387
444
// don't automatically polyfill certain node libraries
388
445
// as we don't care about these implementations and they just add weight
389
446
node : this . nodeSettings ,
390
- } ;
447
+ } as Partial < webpack . Configuration > ;
448
+
449
+ ( configTemplate . plugins as webpack . Plugin [ ] ) . push (
450
+ new DefinePlugin ( {
451
+ 'process.env.MODERN_BUILD' : isModule ,
452
+ 'MODERN_BUILD' : isModule ,
453
+ 'process.env.DEBUG' : cliConfig . debug ,
454
+ 'DEBUG' : cliConfig . debug ,
455
+ } )
456
+ ) ;
391
457
392
458
if ( ! cliConfig . debug )
393
459
{
394
- ( config . optimization as any ) . minimizer . push ( new TerserPlugin ( {
460
+ ( configTemplate . optimization as any ) . minimizer . push ( new TerserPlugin ( {
395
461
cache : true ,
396
462
parallel : true ,
397
463
sourceMap : true ,
@@ -407,7 +473,7 @@ export class Kaba
407
473
try
408
474
{
409
475
const BundleAnalyzerPlugin = require ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin ;
410
- ( config . plugins as any [ ] ) . push ( new BundleAnalyzerPlugin ( ) ) ;
476
+ ( configTemplate . plugins as any [ ] ) . push ( new BundleAnalyzerPlugin ( ) ) ;
411
477
}
412
478
catch ( e )
413
479
{
@@ -428,96 +494,9 @@ export class Kaba
428
494
429
495
}
430
496
431
- return config ;
432
- }
433
-
434
-
435
- /**
436
- * Builds the specialized webpack config for a legacy / module build
437
- */
438
- private buildWebpackConfig ( entry : string , entryFile : string , cliConfig : kaba . CliConfig , isModule : boolean ) : Partial < webpack . Configuration >
439
- {
440
- const babelLoader = {
441
- loader : "babel-loader?cacheDirectory" ,
442
- options : {
443
- babelrc : false ,
444
- presets : [
445
- [ isModule ? kabaBabelPreset . modern : kabaBabelPreset . legacy ] ,
446
- ] ,
447
- } ,
448
- } ;
449
-
450
- let typeScriptConfig = path . join (
451
- this . libRoot ,
452
- "configs" ,
453
- isModule ? "tsconfig.modern.json" : "tsconfig.legacy.json" ,
454
- ) ;
455
-
456
- const entryObjKey = isModule ? `_modern.${ entry } ` : entry ;
457
-
458
- let configTemplate = {
459
- name : isModule ? "modern" : "legacy" ,
460
- entry : {
461
- [ entryObjKey ] : entryFile ,
462
- } ,
463
-
464
- // output
465
- output : {
466
- path : path . join ( this . outputPaths . base , this . outputPaths . js , isModule ? "modern" : "legacy" ) ,
467
- filename : this . hashFileNames ? '[name].[chunkhash].js' : '[name].js' ,
468
- // the slash at the end is required of the public path entries
469
- publicPath : path . join ( this . publicPath , isModule ? "modern/" : "legacy/" ) ,
470
- pathinfo : cliConfig . debug ,
471
- } ,
472
-
473
- // module
474
- module : {
475
- rules : [
476
- // TypeScript
477
- {
478
- test : / \. t s x ? $ / ,
479
- use : [
480
- 'cache-loader' ,
481
- babelLoader ,
482
- {
483
- loader : "ts-loader" ,
484
- options : {
485
- context : this . cwd ,
486
- configFile : typeScriptConfig ,
487
- errorFormatter : ( message , colors ) => typeScriptErrorFormatter ( message , colors , this . cwd ) ,
488
- } ,
489
- } ,
490
- ] ,
491
- } ,
492
-
493
- // Babel
494
- {
495
- test : / \. m ? j s x ? $ / ,
496
- use : [ 'cache-loader' , babelLoader ] ,
497
- } ,
498
-
499
- // content files
500
- {
501
- test : / \. ( s v g | t x t ) $ / ,
502
- loader : "raw-loader" ,
503
- } ,
504
- ] as webpack . RuleSetRule [ ] ,
505
- } ,
506
-
507
- // plugins
508
- plugins : [
509
- new CleanWebpackPlugin ( ) ,
510
- new DefinePlugin ( {
511
- 'process.env.MODERN_BUILD' : isModule ,
512
- 'MODERN_BUILD' : isModule ,
513
- 'process.env.DEBUG' : cliConfig . debug ,
514
- 'DEBUG' : cliConfig . debug ,
515
- } ) ,
516
- ] ,
517
- } ;
518
-
519
- if ( ! isModule ) {
520
- configTemplate . module . rules . push ( {
497
+ if ( ! isModule )
498
+ {
499
+ ( configTemplate . module as webpack . Module ) . rules . push ( {
521
500
// ESLint
522
501
test : / \. m ? j s x ? $ / ,
523
502
// only lint files that are in the project dir & exclude tests, vendor and node_modules
0 commit comments