File tree 1 file changed +24
-2
lines changed
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ interface Compilation {
13
13
assets : { [ key : string ] : Asset }
14
14
}
15
15
16
+ interface Config {
17
+ filter ?( fileName : string ) : boolean
18
+ }
19
+
16
20
export default class Plugin
17
21
{
18
22
static addStyle ( html : string , style : string ) {
@@ -26,17 +30,35 @@ export default class Plugin
26
30
) ;
27
31
}
28
32
33
+ private config : Config ;
34
+
29
35
private css : File = { } ;
36
+
30
37
private html : File = { } ;
31
38
39
+ constructor ( config : Config ) {
40
+ this . config = config ;
41
+ }
42
+
43
+ private filter ( fileName : string ) : boolean {
44
+ if ( typeof this . config . filter === 'function' ) {
45
+ return this . config . filter ( fileName ) ;
46
+ } else {
47
+ return true ;
48
+ }
49
+ }
50
+
32
51
private prepare ( { assets } : Compilation ) {
33
52
const isCSS = is ( 'css' ) ;
34
53
const isHTML = is ( 'html' ) ;
35
54
36
55
Object . keys ( assets ) . forEach ( ( fileName ) => {
37
56
if ( isCSS ( fileName ) ) {
38
- this . css [ fileName ] = assets [ fileName ] . source ( ) ;
39
- delete assets [ fileName ] ;
57
+ const isCurrentFileNeedsToBeInlined = this . filter ( fileName ) ;
58
+ if ( isCurrentFileNeedsToBeInlined ) {
59
+ this . css [ fileName ] = assets [ fileName ] . source ( ) ;
60
+ delete assets [ fileName ] ;
61
+ }
40
62
} else if ( isHTML ( fileName ) ) {
41
63
this . html [ fileName ] = assets [ fileName ] . source ( ) ;
42
64
}
You can’t perform that action at this time.
0 commit comments