@@ -354,13 +354,7 @@ function getImportCode(loaderContext, imports, options) {
354354 return code ? `// Imports\n${ code } ` : '' ;
355355}
356356
357- function getModuleCode (
358- result ,
359- apiImports ,
360- urlReplacements ,
361- icssReplacements ,
362- options
363- ) {
357+ function getModuleCode ( result , apiImports , replacements , options ) {
364358 if ( options . modules . exportOnlyLocals === true ) {
365359 return 'var ___CSS_LOADER_EXPORT___ = {};\n' ;
366360 }
@@ -383,33 +377,35 @@ function getModuleCode(
383377 ) } ${ media ? `, ${ JSON . stringify ( media ) } ` : '' } ]);\n`;
384378 }
385379
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 ;
388382
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 ;
394385
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 ( ', ' ) } }` : '' ;
402391
403- for ( const replacement of icssReplacements ) {
404- const { replacementName, importName, localName } = replacement ;
392+ beforeCode += `var ${ replacementName } = ___CSS_LOADER_GET_URL_IMPORT___(${ importName } ${ preparedOptions } );\n` ;
405393
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+ }
413409 }
414410
415411 return `${ beforeCode } // Module\n___CSS_LOADER_EXPORT___.push([module.id, ${ code } , ""${ sourceMapValue } ]);\n` ;
@@ -421,7 +417,7 @@ function dashesCamelCase(str) {
421417 ) ;
422418}
423419
424- function getExportCode ( exports , icssReplacements , options ) {
420+ function getExportCode ( exports , replacements , options ) {
425421 let code = '' ;
426422 let localsCode = '' ;
427423
@@ -476,16 +472,25 @@ function getExportCode(exports, icssReplacements, options) {
476472 }
477473 }
478474
479- for ( const replacement of icssReplacements ) {
480- const { replacementName, importName , localName } = replacement ;
475+ for ( const replacement of replacements ) {
476+ const { replacementName, type } = replacement ;
481477
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+ }
489494 }
490495
491496 if ( localsCode ) {
0 commit comments