@@ -274,12 +274,24 @@ export class Kaba
274
274
275
275
if ( Object . keys ( this . jsEntries ) . length )
276
276
{
277
+ const compilerConfigs : kaba . WebpackBuildConfig [ ] = [ ] ;
278
+
279
+ Object . keys ( this . jsEntries ) . forEach ( ( entry : string ) => {
280
+ if ( this . buildModern )
281
+ {
282
+ compilerConfigs . push ( this . buildWebpackConfig ( entry , this . jsEntries [ entry ] , cliConfig , true ) ) ;
283
+ }
284
+ } ) ;
285
+
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
+
277
292
jsConfig = {
278
293
common : this . buildWebpackCommon ( cliConfig ) ,
279
- module : this . buildModern
280
- ? this . buildWebpackConfigs ( cliConfig , true )
281
- : null ,
282
- legacy : this . buildWebpackConfigs ( cliConfig , false ) ,
294
+ configs : compilerConfigs ,
283
295
javaScriptDependenciesFileName : this . javaScriptDependenciesFileName ,
284
296
basePath : path . join ( this . outputPaths . base , this . outputPaths . js ) ,
285
297
} ;
@@ -423,7 +435,7 @@ export class Kaba
423
435
/**
424
436
* Builds the specialized webpack config for a legacy / module build
425
437
*/
426
- private buildWebpackConfigs ( cliConfig : kaba . CliConfig , isModule : boolean ) : Partial < webpack . Configuration > [ ]
438
+ private buildWebpackConfig ( entry : string , entryFile : string , cliConfig : kaba . CliConfig , isModule : boolean ) : Partial < webpack . Configuration >
427
439
{
428
440
const babelLoader = {
429
441
loader : "babel-loader?cacheDirectory" ,
@@ -435,26 +447,20 @@ export class Kaba
435
447
} ,
436
448
} ;
437
449
438
- let entries = this . jsEntries ;
439
-
440
- if ( isModule )
441
- {
442
- entries = { } ;
443
- Object . keys ( this . jsEntries ) . forEach (
444
- entry =>
445
- {
446
- entries [ `_modern.${ entry } ` ] = this . jsEntries [ entry ] ;
447
- } ,
448
- ) ;
449
- }
450
-
451
450
let typeScriptConfig = path . join (
452
451
this . libRoot ,
453
452
"configs" ,
454
453
isModule ? "tsconfig.modern.json" : "tsconfig.legacy.json" ,
455
454
) ;
456
455
456
+ const entryObjKey = isModule ? `_modern.${ entry } ` : entry ;
457
+
457
458
let configTemplate = {
459
+ name : isModule ? "modern" : "legacy" ,
460
+ entry : {
461
+ [ entryObjKey ] : entryFile ,
462
+ } ,
463
+
458
464
// output
459
465
output : {
460
466
path : path . join ( this . outputPaths . base , this . outputPaths . js , isModule ? "modern" : "legacy" ) ,
@@ -495,7 +501,7 @@ export class Kaba
495
501
test : / \. ( s v g | t x t ) $ / ,
496
502
loader : "raw-loader" ,
497
503
} ,
498
- ] ,
504
+ ] as webpack . RuleSetRule [ ] ,
499
505
} ,
500
506
501
507
// plugins
@@ -510,45 +516,26 @@ export class Kaba
510
516
] ,
511
517
} ;
512
518
513
- return Object . keys ( entries ) . map ( entryFile =>
514
- {
515
- let config = Object . assign ( { } , configTemplate , {
516
- entry : {
517
- [ entryFile ] : entries [ entryFile ] ,
519
+ if ( ! isModule ) {
520
+ configTemplate . module . rules . push ( {
521
+ // ESLint
522
+ test : / \. m ? j s x ? $ / ,
523
+ // only lint files that are in the project dir & exclude tests, vendor and node_modules
524
+ include : ( path ) => path . startsWith ( this . cwd ) && ! / n o d e _ m o d u l e s | t e s t s | v e n d o r / . test ( path ) ,
525
+ loader : "eslint-loader" ,
526
+ options : {
527
+ cache : true ,
528
+ configFile : path . join ( this . libRoot , "configs/.eslintrc.yml" ) ,
529
+ fix : cliConfig . fix ,
530
+ parser : "babel-eslint" ,
531
+ quiet : ! cliConfig . lint ,
532
+ // always only emit a warning, so to actually never fail the webpack build
533
+ emitWarning : true ,
518
534
} ,
519
- } ) as Partial < webpack . Configuration > ;
520
-
521
- if ( ! isModule && undefined !== config . module )
522
- {
523
- config . module = Object . assign ( { } , config . module ) ;
524
- let rules : webpack . RuleSetRule [ ] = [ ] ;
525
-
526
- config . module . rules . forEach ( rule => {
527
- rules . push ( rule ) ;
528
- } ) ;
529
-
530
- rules . push ( {
531
- // ESLint
532
- test : / \. m ? j s x ? $ / ,
533
- // only lint files that are in the project dir & exclude tests, vendor and node_modules
534
- include : ( path ) => path . startsWith ( this . cwd ) && ! / n o d e _ m o d u l e s | t e s t s | v e n d o r / . test ( path ) ,
535
- loader : "eslint-loader" ,
536
- options : {
537
- cache : true ,
538
- configFile : path . join ( this . libRoot , "configs/.eslintrc.yml" ) ,
539
- fix : cliConfig . fix ,
540
- parser : "babel-eslint" ,
541
- quiet : ! cliConfig . lint ,
542
- // always only emit a warning, so to actually never fail the webpack build
543
- emitWarning : true ,
544
- } ,
545
- } ) ;
546
-
547
- config . module . rules = rules ;
548
- }
535
+ } ) ;
536
+ }
549
537
550
- return config ;
551
- } ) ;
538
+ return configTemplate ;
552
539
}
553
540
}
554
541
0 commit comments