1
- import fs from 'fs' ;
2
- import path from 'path' ;
3
-
4
1
import webpack from 'webpack' ;
5
2
import sources from 'webpack-sources' ;
6
3
10
7
util : { createHash } ,
11
8
} = webpack ;
12
9
13
- const NS = path . dirname ( fs . realpathSync ( __filename ) ) ;
10
+ const MODULE_TYPE = 'css/mini-extract' ;
14
11
15
12
const pluginName = 'mini-css-extract-plugin' ;
16
13
@@ -44,7 +41,7 @@ class CssDependencyTemplate {
44
41
45
42
class CssModule extends webpack . Module {
46
43
constructor ( dependency ) {
47
- super ( NS , dependency . context ) ;
44
+ super ( MODULE_TYPE , dependency . context ) ;
48
45
this . _identifier = dependency . identifier ;
49
46
this . _identifierIndex = dependency . identifierIndex ;
50
47
this . content = dependency . content ;
@@ -141,7 +138,7 @@ class MiniCssExtractPlugin {
141
138
compilation . hooks . normalModuleLoader . tap ( pluginName , ( lc , m ) => {
142
139
const loaderContext = lc ;
143
140
const module = m ;
144
- loaderContext [ NS ] = ( content ) => {
141
+ loaderContext [ MODULE_TYPE ] = ( content ) => {
145
142
if ( ! Array . isArray ( content ) && content != null ) {
146
143
throw new Error (
147
144
`Exported value was not extracted as an array: ${ JSON . stringify (
@@ -169,7 +166,7 @@ class MiniCssExtractPlugin {
169
166
pluginName ,
170
167
( result , { chunk } ) => {
171
168
const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
172
- ( module ) => module . type === NS
169
+ ( module ) => module . type === MODULE_TYPE
173
170
) ;
174
171
if ( renderedModules . length > 0 ) {
175
172
result . push ( {
@@ -183,10 +180,10 @@ class MiniCssExtractPlugin {
183
180
filenameTemplate : this . options . filename ,
184
181
pathOptions : {
185
182
chunk,
186
- contentHashType : NS ,
183
+ contentHashType : MODULE_TYPE ,
187
184
} ,
188
185
identifier : `${ pluginName } .${ chunk . id } ` ,
189
- hash : chunk . contentHash [ NS ] ,
186
+ hash : chunk . contentHash [ MODULE_TYPE ] ,
190
187
} ) ;
191
188
}
192
189
}
@@ -195,7 +192,7 @@ class MiniCssExtractPlugin {
195
192
pluginName ,
196
193
( result , { chunk } ) => {
197
194
const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
198
- ( module ) => module . type === NS
195
+ ( module ) => module . type === MODULE_TYPE
199
196
) ;
200
197
if ( renderedModules . length > 0 ) {
201
198
result . push ( {
@@ -209,10 +206,10 @@ class MiniCssExtractPlugin {
209
206
filenameTemplate : this . options . chunkFilename ,
210
207
pathOptions : {
211
208
chunk,
212
- contentHashType : NS ,
209
+ contentHashType : MODULE_TYPE ,
213
210
} ,
214
211
identifier : `${ pluginName } .${ chunk . id } ` ,
215
- hash : chunk . contentHash [ NS ] ,
212
+ hash : chunk . contentHash [ MODULE_TYPE ] ,
216
213
} ) ;
217
214
}
218
215
}
@@ -226,7 +223,9 @@ class MiniCssExtractPlugin {
226
223
}
227
224
if ( REGEXP_CONTENTHASH . test ( chunkFilename ) ) {
228
225
hash . update (
229
- JSON . stringify ( chunk . getChunkMaps ( true ) . contentHash [ NS ] || { } )
226
+ JSON . stringify (
227
+ chunk . getChunkMaps ( true ) . contentHash [ MODULE_TYPE ] || { }
228
+ )
230
229
) ;
231
230
}
232
231
if ( REGEXP_NAME . test ( chunkFilename ) ) {
@@ -239,12 +238,12 @@ class MiniCssExtractPlugin {
239
238
const { hashFunction, hashDigest, hashDigestLength } = outputOptions ;
240
239
const hash = createHash ( hashFunction ) ;
241
240
for ( const m of chunk . modulesIterable ) {
242
- if ( m . type === NS ) {
241
+ if ( m . type === MODULE_TYPE ) {
243
242
m . updateHash ( hash ) ;
244
243
}
245
244
}
246
245
const { contentHash } = chunk ;
247
- contentHash [ NS ] = hash
246
+ contentHash [ MODULE_TYPE ] = hash
248
247
. digest ( hashDigest )
249
248
. substring ( 0 , hashDigestLength ) ;
250
249
} ) ;
@@ -294,14 +293,14 @@ class MiniCssExtractPlugin {
294
293
) } [chunkId] + "`;
295
294
} ,
296
295
contentHash : {
297
- [ NS ] : `" + ${ JSON . stringify (
298
- chunkMaps . contentHash [ NS ]
296
+ [ MODULE_TYPE ] : `" + ${ JSON . stringify (
297
+ chunkMaps . contentHash [ MODULE_TYPE ]
299
298
) } [chunkId] + "`,
300
299
} ,
301
300
contentHashWithLength : {
302
- [ NS ] : ( length ) => {
301
+ [ MODULE_TYPE ] : ( length ) => {
303
302
const shortContentHashMap = { } ;
304
- const contentHash = chunkMaps . contentHash [ NS ] ;
303
+ const contentHash = chunkMaps . contentHash [ MODULE_TYPE ] ;
305
304
for ( const chunkId of Object . keys ( contentHash ) ) {
306
305
if ( typeof contentHash [ chunkId ] === 'string' ) {
307
306
shortContentHashMap [ chunkId ] = contentHash [
@@ -318,7 +317,7 @@ class MiniCssExtractPlugin {
318
317
chunkMaps . name
319
318
) } [chunkId]||chunkId) + "`,
320
319
} ,
321
- contentHashType : NS ,
320
+ contentHashType : MODULE_TYPE ,
322
321
}
323
322
) ;
324
323
return Template . asString ( [
@@ -382,7 +381,7 @@ class MiniCssExtractPlugin {
382
381
const obj = { } ;
383
382
for ( const chunk of mainChunk . getAllAsyncChunks ( ) ) {
384
383
for ( const module of chunk . modulesIterable ) {
385
- if ( module . type === NS ) {
384
+ if ( module . type === MODULE_TYPE ) {
386
385
obj [ chunk . id ] = 1 ;
387
386
break ;
388
387
}
0 commit comments