@@ -11,6 +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
16
15
17
interface Entries
16
18
{
@@ -29,6 +31,22 @@ interface Externals
29
31
[ name : string ] : string ;
30
32
}
31
33
34
+ /**
35
+ * Determines whether a file should processed by the asset pipeline.
36
+ */
37
+ function isAllowedPath ( path : string , allowedPaths : CompiledNpmPackagesMapping ) : boolean
38
+ {
39
+ const match = PACKAGE_MATCHER . exec ( path ) ;
40
+
41
+ // not in node_modules, so always process
42
+ if ( ! match )
43
+ {
44
+ return true ;
45
+ }
46
+
47
+ // only allow the allowed package names
48
+ return true === allowedPaths [ ( match . groups as any ) . package ] ;
49
+ }
32
50
33
51
/**
34
52
* Main Kaba class
@@ -52,6 +70,11 @@ export class Kaba
52
70
private hashFileNames : boolean = true ;
53
71
private buildModern : boolean = true ;
54
72
private nodeSettings : webpack . Node | false = false ;
73
+ private compiledNpmPackages : CompiledNpmPackagesMapping = {
74
+ preact : true ,
75
+ mojave : true ,
76
+ '@mayd' : true ,
77
+ } ;
55
78
56
79
57
80
/**
@@ -77,6 +100,16 @@ export class Kaba
77
100
}
78
101
79
102
103
+ /**
104
+ * Defines which npm packages are compiled
105
+ */
106
+ public compileNpmPackages ( modules : string [ ] ) : this
107
+ {
108
+ modules . forEach ( module => this . compiledNpmPackages [ module ] = true ) ;
109
+ return this ;
110
+ }
111
+
112
+
80
113
/**
81
114
* Adds Sass entries
82
115
*/
@@ -369,12 +402,14 @@ export class Kaba
369
402
} ,
370
403
} ,
371
404
] ,
405
+ include : ( path : string ) => isAllowedPath ( path , this . compiledNpmPackages ) ,
372
406
} ,
373
407
374
408
// Babel
375
409
{
376
410
test : / \. m ? j s x ? $ / ,
377
411
use : [ 'cache-loader' , babelLoader ] ,
412
+ include : ( path : string ) => isAllowedPath ( path , this . compiledNpmPackages ) ,
378
413
} ,
379
414
380
415
// content files
@@ -383,11 +418,22 @@ export class Kaba
383
418
loader : "raw-loader" ,
384
419
} ,
385
420
386
- // ignore CSS files
421
+ // Try to avoid compiling CSS, but if there is CSS then inject it into the head
387
422
{
388
423
test : / \. c s s $ / ,
389
- loader : "ignore-loader" ,
390
- }
424
+ use : [
425
+ {
426
+ loader : 'style-loader' ,
427
+ options : {
428
+ injectType : 'singletonStyleTag' ,
429
+ } ,
430
+ } ,
431
+ {
432
+ loader : 'postcss-loader' ,
433
+ options : this . postCssLoaderOptions ,
434
+ } ,
435
+ ] ,
436
+ } ,
391
437
] ,
392
438
} ,
393
439
0 commit comments