@@ -11,8 +11,8 @@ const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack
11
11
const ProgressBarPlugin = require ( 'progress-bar-webpack-plugin' ) ;
12
12
const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' ) ;
13
13
14
- const PACKAGE_MATCHER = / \/ n o d e _ m o d u l e s \/ (?< package > [ ^ \/ ] + ) \/ / ;
15
- interface CompiledNpmPackagesMapping { [ name : string ] : true }
14
+ const PACKAGE_MATCHER = / \/ n o d e _ m o d u l e s \/ (?< package > (?: @ [ ^ @ \/ ] + \/ ) ? [ ^ @ \/ ] + ) \/ / ;
15
+ type IgnoredNpmPackagesMapping = Array < RegExp | string > ;
16
16
interface PostCssLoaderOptions { [ key : string ] : any }
17
17
18
18
interface Entries
@@ -35,7 +35,7 @@ interface Externals
35
35
/**
36
36
* Determines whether a file should processed by the asset pipeline.
37
37
*/
38
- function isAllowedPath ( path : string , allowedPaths : CompiledNpmPackagesMapping ) : boolean
38
+ function isAllowedPath ( path : string , ignoredPackages : IgnoredNpmPackagesMapping ) : boolean
39
39
{
40
40
const match = PACKAGE_MATCHER . exec ( path ) ;
41
41
@@ -45,8 +45,27 @@ function isAllowedPath (path: string, allowedPaths: CompiledNpmPackagesMapping)
45
45
return true ;
46
46
}
47
47
48
- // only allow the allowed package names
49
- return true === allowedPaths [ ( match . groups as any ) . package ] ;
48
+ const packageNameToCompile = ( match . groups as any ) . package ;
49
+
50
+ const length = ignoredPackages . length ;
51
+ for ( let i = 0 ; i < length ; ++ i )
52
+ {
53
+ const ignoredPackage = ignoredPackages [ i ] ;
54
+
55
+ if ( typeof ignoredPackage == "string" )
56
+ {
57
+ if ( ignoredPackage === packageNameToCompile )
58
+ {
59
+ return false ;
60
+ }
61
+ }
62
+ else if ( ignoredPackage . test ( packageNameToCompile ) )
63
+ {
64
+ return false ;
65
+ }
66
+ }
67
+
68
+ return true ;
50
69
}
51
70
52
71
/**
@@ -71,12 +90,10 @@ export class Kaba
71
90
private hashFileNames : boolean = true ;
72
91
private buildModern : boolean = true ;
73
92
private nodeSettings : webpack . Node | false = false ;
74
- private compiledNpmPackages : CompiledNpmPackagesMapping = {
75
- '@becklyn' : true ,
76
- '@mayd' : true ,
77
- mojave : true ,
78
- preact : true ,
79
- } ;
93
+ private ignoredNpmPackages : IgnoredNpmPackagesMapping = [
94
+ / ^ @ b a b e l / ,
95
+ / ^ r e g e n e r a t o r - / ,
96
+ ] ;
80
97
private postCssLoaderOptions : PostCssLoaderOptions = { } ;
81
98
82
99
@@ -104,11 +121,11 @@ export class Kaba
104
121
105
122
106
123
/**
107
- * Defines which npm packages are compiled
124
+ * Defines which npm packages are NOT compiled with babel
108
125
*/
109
- public compileNpmPackages ( modules : string [ ] ) : this
126
+ public ignoreNpmPackages ( modules : Array < string | RegExp > ) : this
110
127
{
111
- modules . forEach ( module => this . compiledNpmPackages [ module ] = true ) ;
128
+ this . ignoredNpmPackages = this . ignoredNpmPackages . concat ( modules ) ;
112
129
return this ;
113
130
}
114
131
@@ -415,14 +432,14 @@ export class Kaba
415
432
} ,
416
433
} ,
417
434
] ,
418
- include : ( path : string ) => isAllowedPath ( path , this . compiledNpmPackages ) ,
435
+ include : ( path : string ) => isAllowedPath ( path , this . ignoredNpmPackages ) ,
419
436
} ,
420
437
421
438
// Babel
422
439
{
423
440
test : / \. m ? j s x ? $ / ,
424
441
use : [ 'cache-loader' , babelLoader ] ,
425
- include : ( path : string ) => isAllowedPath ( path , this . compiledNpmPackages ) ,
442
+ include : ( path : string ) => isAllowedPath ( path , this . ignoredNpmPackages ) ,
426
443
} ,
427
444
428
445
// content files
0 commit comments