1- import fs from 'fs' ;
2- import path from 'path' ;
3-
41import webpack from 'webpack' ;
52import sources from 'webpack-sources' ;
63
107 util : { createHash } ,
118} = webpack ;
129
13- const NS = path . dirname ( fs . realpathSync ( __filename ) ) ;
10+ const MODULE_TYPE = 'css/mini-extract' ;
1411
1512const pluginName = 'mini-css-extract-plugin' ;
1613
@@ -44,7 +41,7 @@ class CssDependencyTemplate {
4441
4542class CssModule extends webpack . Module {
4643 constructor ( dependency ) {
47- super ( NS , dependency . context ) ;
44+ super ( MODULE_TYPE , dependency . context ) ;
4845 this . _identifier = dependency . identifier ;
4946 this . _identifierIndex = dependency . identifierIndex ;
5047 this . content = dependency . content ;
@@ -141,7 +138,7 @@ class MiniCssExtractPlugin {
141138 compilation . hooks . normalModuleLoader . tap ( pluginName , ( lc , m ) => {
142139 const loaderContext = lc ;
143140 const module = m ;
144- loaderContext [ NS ] = ( content ) => {
141+ loaderContext [ MODULE_TYPE ] = ( content ) => {
145142 if ( ! Array . isArray ( content ) && content != null ) {
146143 throw new Error (
147144 `Exported value was not extracted as an array: ${ JSON . stringify (
@@ -169,7 +166,7 @@ class MiniCssExtractPlugin {
169166 pluginName ,
170167 ( result , { chunk } ) => {
171168 const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
172- ( module ) => module . type === NS
169+ ( module ) => module . type === MODULE_TYPE
173170 ) ;
174171 if ( renderedModules . length > 0 ) {
175172 result . push ( {
@@ -183,10 +180,10 @@ class MiniCssExtractPlugin {
183180 filenameTemplate : this . options . filename ,
184181 pathOptions : {
185182 chunk,
186- contentHashType : NS ,
183+ contentHashType : MODULE_TYPE ,
187184 } ,
188185 identifier : `${ pluginName } .${ chunk . id } ` ,
189- hash : chunk . contentHash [ NS ] ,
186+ hash : chunk . contentHash [ MODULE_TYPE ] ,
190187 } ) ;
191188 }
192189 }
@@ -195,7 +192,7 @@ class MiniCssExtractPlugin {
195192 pluginName ,
196193 ( result , { chunk } ) => {
197194 const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
198- ( module ) => module . type === NS
195+ ( module ) => module . type === MODULE_TYPE
199196 ) ;
200197 if ( renderedModules . length > 0 ) {
201198 result . push ( {
@@ -209,10 +206,10 @@ class MiniCssExtractPlugin {
209206 filenameTemplate : this . options . chunkFilename ,
210207 pathOptions : {
211208 chunk,
212- contentHashType : NS ,
209+ contentHashType : MODULE_TYPE ,
213210 } ,
214211 identifier : `${ pluginName } .${ chunk . id } ` ,
215- hash : chunk . contentHash [ NS ] ,
212+ hash : chunk . contentHash [ MODULE_TYPE ] ,
216213 } ) ;
217214 }
218215 }
@@ -226,7 +223,9 @@ class MiniCssExtractPlugin {
226223 }
227224 if ( REGEXP_CONTENTHASH . test ( chunkFilename ) ) {
228225 hash . update (
229- JSON . stringify ( chunk . getChunkMaps ( true ) . contentHash [ NS ] || { } )
226+ JSON . stringify (
227+ chunk . getChunkMaps ( true ) . contentHash [ MODULE_TYPE ] || { }
228+ )
230229 ) ;
231230 }
232231 if ( REGEXP_NAME . test ( chunkFilename ) ) {
@@ -239,12 +238,12 @@ class MiniCssExtractPlugin {
239238 const { hashFunction, hashDigest, hashDigestLength } = outputOptions ;
240239 const hash = createHash ( hashFunction ) ;
241240 for ( const m of chunk . modulesIterable ) {
242- if ( m . type === NS ) {
241+ if ( m . type === MODULE_TYPE ) {
243242 m . updateHash ( hash ) ;
244243 }
245244 }
246245 const { contentHash } = chunk ;
247- contentHash [ NS ] = hash
246+ contentHash [ MODULE_TYPE ] = hash
248247 . digest ( hashDigest )
249248 . substring ( 0 , hashDigestLength ) ;
250249 } ) ;
@@ -294,14 +293,14 @@ class MiniCssExtractPlugin {
294293 ) } [chunkId] + "`;
295294 } ,
296295 contentHash : {
297- [ NS ] : `" + ${ JSON . stringify (
298- chunkMaps . contentHash [ NS ]
296+ [ MODULE_TYPE ] : `" + ${ JSON . stringify (
297+ chunkMaps . contentHash [ MODULE_TYPE ]
299298 ) } [chunkId] + "`,
300299 } ,
301300 contentHashWithLength : {
302- [ NS ] : ( length ) => {
301+ [ MODULE_TYPE ] : ( length ) => {
303302 const shortContentHashMap = { } ;
304- const contentHash = chunkMaps . contentHash [ NS ] ;
303+ const contentHash = chunkMaps . contentHash [ MODULE_TYPE ] ;
305304 for ( const chunkId of Object . keys ( contentHash ) ) {
306305 if ( typeof contentHash [ chunkId ] === 'string' ) {
307306 shortContentHashMap [ chunkId ] = contentHash [
@@ -318,7 +317,7 @@ class MiniCssExtractPlugin {
318317 chunkMaps . name
319318 ) } [chunkId]||chunkId) + "`,
320319 } ,
321- contentHashType : NS ,
320+ contentHashType : MODULE_TYPE ,
322321 }
323322 ) ;
324323 return Template . asString ( [
@@ -382,7 +381,7 @@ class MiniCssExtractPlugin {
382381 const obj = { } ;
383382 for ( const chunk of mainChunk . getAllAsyncChunks ( ) ) {
384383 for ( const module of chunk . modulesIterable ) {
385- if ( module . type === NS ) {
384+ if ( module . type === MODULE_TYPE ) {
386385 obj [ chunk . id ] = 1 ;
387386 break ;
388387 }
0 commit comments