@@ -354,13 +354,7 @@ function getImportCode(loaderContext, imports, options) {
354
354
return code ? `// Imports\n${ code } ` : '' ;
355
355
}
356
356
357
- function getModuleCode (
358
- result ,
359
- apiImports ,
360
- urlReplacements ,
361
- icssReplacements ,
362
- options
363
- ) {
357
+ function getModuleCode ( result , apiImports , replacements , options ) {
364
358
if ( options . modules . exportOnlyLocals === true ) {
365
359
return 'var ___CSS_LOADER_EXPORT___ = {};\n' ;
366
360
}
@@ -383,33 +377,35 @@ function getModuleCode(
383
377
) } ${ media ? `, ${ JSON . stringify ( media ) } ` : '' } ]);\n`;
384
378
}
385
379
386
- for ( const item of urlReplacements ) {
387
- const { replacementName, importName, hash , needQuotes } = item ;
380
+ for ( const replacement of replacements ) {
381
+ const { replacementName, importName, type } = replacement ;
388
382
389
- const getUrlOptions = [ ]
390
- . concat ( hash ? [ `hash: ${ JSON . stringify ( hash ) } ` ] : [ ] )
391
- . concat ( needQuotes ? 'needQuotes: true' : [ ] ) ;
392
- const preparedOptions =
393
- getUrlOptions . length > 0 ? `, { ${ getUrlOptions . join ( ', ' ) } }` : '' ;
383
+ if ( type === 'url' ) {
384
+ const { hash, needQuotes } = replacement ;
394
385
395
- beforeCode += `var ${ replacementName } = ___CSS_LOADER_GET_URL_IMPORT___(${ importName } ${ preparedOptions } );\n` ;
396
-
397
- code = code . replace (
398
- new RegExp ( replacementName , 'g' ) ,
399
- ( ) => `" + ${ replacementName } + "`
400
- ) ;
401
- }
386
+ const getUrlOptions = [ ]
387
+ . concat ( hash ? [ `hash: ${ JSON . stringify ( hash ) } ` ] : [ ] )
388
+ . concat ( needQuotes ? 'needQuotes: true' : [ ] ) ;
389
+ const preparedOptions =
390
+ getUrlOptions . length > 0 ? `, { ${ getUrlOptions . join ( ', ' ) } }` : '' ;
402
391
403
- for ( const replacement of icssReplacements ) {
404
- const { replacementName, importName, localName } = replacement ;
392
+ beforeCode += `var ${ replacementName } = ___CSS_LOADER_GET_URL_IMPORT___(${ importName } ${ preparedOptions } );\n` ;
405
393
406
- code = code . replace ( new RegExp ( replacementName , 'g' ) , ( ) =>
407
- options . modules . namedExport
408
- ? `" + ${ importName } _NAMED___[${ JSON . stringify (
409
- camelCase ( localName )
410
- ) } ] + "`
411
- : `" + ${ importName } .locals[${ JSON . stringify ( localName ) } ] + "`
412
- ) ;
394
+ code = code . replace (
395
+ new RegExp ( replacementName , 'g' ) ,
396
+ ( ) => `" + ${ replacementName } + "`
397
+ ) ;
398
+ } else {
399
+ const { localName } = replacement ;
400
+
401
+ code = code . replace ( new RegExp ( replacementName , 'g' ) , ( ) =>
402
+ options . modules . namedExport
403
+ ? `" + ${ importName } _NAMED___[${ JSON . stringify (
404
+ camelCase ( localName )
405
+ ) } ] + "`
406
+ : `" + ${ importName } .locals[${ JSON . stringify ( localName ) } ] + "`
407
+ ) ;
408
+ }
413
409
}
414
410
415
411
return `${ beforeCode } // Module\n___CSS_LOADER_EXPORT___.push([module.id, ${ code } , ""${ sourceMapValue } ]);\n` ;
@@ -421,7 +417,7 @@ function dashesCamelCase(str) {
421
417
) ;
422
418
}
423
419
424
- function getExportCode ( exports , icssReplacements , options ) {
420
+ function getExportCode ( exports , replacements , options ) {
425
421
let code = '' ;
426
422
let localsCode = '' ;
427
423
@@ -476,16 +472,25 @@ function getExportCode(exports, icssReplacements, options) {
476
472
}
477
473
}
478
474
479
- for ( const replacement of icssReplacements ) {
480
- const { replacementName, importName , localName } = replacement ;
475
+ for ( const replacement of replacements ) {
476
+ const { replacementName, type } = replacement ;
481
477
482
- localsCode = localsCode . replace ( new RegExp ( replacementName , 'g' ) , ( ) =>
483
- options . modules . namedExport
484
- ? `" + ${ importName } _NAMED___[${ JSON . stringify (
485
- camelCase ( localName )
486
- ) } ] + "`
487
- : `" + ${ importName } .locals[${ JSON . stringify ( localName ) } ] + "`
488
- ) ;
478
+ if ( type === 'url' ) {
479
+ localsCode = localsCode . replace (
480
+ new RegExp ( replacementName , 'g' ) ,
481
+ ( ) => `" + ${ replacementName } + "`
482
+ ) ;
483
+ } else {
484
+ const { importName, localName } = replacement ;
485
+
486
+ localsCode = localsCode . replace ( new RegExp ( replacementName , 'g' ) , ( ) =>
487
+ options . modules . namedExport
488
+ ? `" + ${ importName } _NAMED___[${ JSON . stringify (
489
+ camelCase ( localName )
490
+ ) } ] + "`
491
+ : `" + ${ importName } .locals[${ JSON . stringify ( localName ) } ] + "`
492
+ ) ;
493
+ }
489
494
}
490
495
491
496
if ( localsCode ) {
0 commit comments