@@ -3,12 +3,10 @@ import path from 'path';
3
3
import loaderUtils from 'loader-utils' ;
4
4
import { validate } from 'schema-utils' ;
5
5
6
- import { findModuleById , evalModuleCode } from './utils' ;
6
+ import { findModuleById , evalModuleCode , provideLoaderContext } from './utils' ;
7
7
import schema from './loader-options.json' ;
8
8
9
- import MiniCssExtractPlugin from './index' ;
10
-
11
- const pluginName = 'mini-css-extract-plugin' ;
9
+ import MiniCssExtractPlugin , { pluginName , pluginSymbol } from './index' ;
12
10
13
11
function hotLoader ( content , context ) {
14
12
const accept = context . locals
@@ -39,6 +37,12 @@ export function pitch(request) {
39
37
baseDataPath : 'options' ,
40
38
} ) ;
41
39
40
+ if ( ! this [ pluginSymbol ] ) {
41
+ throw new Error (
42
+ "You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started"
43
+ ) ;
44
+ }
45
+
42
46
const loaders = this . loaders . slice ( this . loaderIndex + 1 ) ;
43
47
44
48
this . addDependency ( this . resourcePath ) ;
@@ -104,33 +108,18 @@ export function pitch(request) {
104
108
105
109
new LimitChunkCountPlugin ( { maxChunks : 1 } ) . apply ( childCompiler ) ;
106
110
107
- const NormalModule = webpack . NormalModule
108
- ? webpack . NormalModule
109
- : // eslint-disable-next-line global-require
110
- require ( 'webpack/lib/NormalModule' ) ;
111
-
112
- childCompiler . hooks . thisCompilation . tap (
113
- `${ pluginName } loader` ,
114
- ( compilation ) => {
115
- const normalModuleHook =
116
- typeof NormalModule . getCompilationHooks !== 'undefined'
117
- ? NormalModule . getCompilationHooks ( compilation ) . loader
118
- : compilation . hooks . normalModuleLoader ;
119
-
120
- normalModuleHook . tap ( `${ pluginName } loader` , ( loaderContext , module ) => {
121
- if ( module . request === request ) {
122
- // eslint-disable-next-line no-param-reassign
123
- module . loaders = loaders . map ( ( loader ) => {
124
- return {
125
- loader : loader . path ,
126
- options : loader . options ,
127
- ident : loader . ident ,
128
- } ;
129
- } ) ;
130
- }
111
+ provideLoaderContext ( childCompiler , `${ pluginName } loader` , ( _ , module ) => {
112
+ if ( module . request === request ) {
113
+ // eslint-disable-next-line no-param-reassign
114
+ module . loaders = loaders . map ( ( loader ) => {
115
+ return {
116
+ loader : loader . path ,
117
+ options : loader . options ,
118
+ ident : loader . ident ,
119
+ } ;
131
120
} ) ;
132
121
}
133
- ) ;
122
+ } ) ;
134
123
135
124
let source ;
136
125
@@ -203,12 +192,6 @@ export function pitch(request) {
203
192
const count = identifierCountMap . get ( dependency . identifier ) || 0 ;
204
193
const CssDependency = MiniCssExtractPlugin . getCssDependency ( webpack ) ;
205
194
206
- if ( ! CssDependency ) {
207
- throw new Error (
208
- "You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started"
209
- ) ;
210
- }
211
-
212
195
this . _module . addDependency (
213
196
( lastDep = new CssDependency ( dependency , dependency . context , count ) )
214
197
) ;
0 commit comments