@@ -4,6 +4,7 @@ import webpack from 'webpack';
4
4
import sources from 'webpack-sources' ;
5
5
6
6
import validateOptions from 'schema-utils' ;
7
+ import { SyncWaterfallHook } from 'tapable' ;
7
8
8
9
import CssDependency from './CssDependency' ;
9
10
import schema from './plugin-options.json' ;
@@ -24,6 +25,8 @@ const REGEXP_NAME = /\[name\]/i;
24
25
const REGEXP_PLACEHOLDERS = / \[ ( n a m e | i d | c h u n k h a s h ) \] / g;
25
26
const DEFAULT_FILENAME = '[name].css' ;
26
27
28
+ const compilerHookMap = new WeakMap ( ) ;
29
+
27
30
class CssDependencyTemplate {
28
31
apply ( ) { }
29
32
}
@@ -127,6 +130,17 @@ class MiniCssExtractPlugin {
127
130
}
128
131
}
129
132
133
+ static getCompilerHooks ( compiler ) {
134
+ let hooks = compilerHookMap . get ( compiler ) ;
135
+ if ( ! hooks ) {
136
+ hooks = {
137
+ customize : new SyncWaterfallHook ( [ 'source' ] ) ,
138
+ } ;
139
+ compilerHookMap . set ( compiler , hooks ) ;
140
+ }
141
+ return hooks ;
142
+ }
143
+
130
144
apply ( compiler ) {
131
145
compiler . hooks . thisCompilation . tap ( pluginName , ( compilation ) => {
132
146
compilation . dependencyFactories . set (
@@ -376,6 +390,9 @@ class MiniCssExtractPlugin {
376
390
'}' ,
377
391
] )
378
392
: '' ,
393
+ MiniCssExtractPlugin . getCompilerHooks (
394
+ compiler
395
+ ) . customize . call ( '' ) ,
379
396
'var head = document.getElementsByTagName("head")[0];' ,
380
397
'head.appendChild(linkTag);' ,
381
398
] ) ,
0 commit comments