@@ -125,7 +125,7 @@ module.exports = function loader(content, map) {
125125
126126 const messages = result . messages || [ ] ;
127127 const { camelCase, exportOnlyLocals, importLoaders } = options ;
128- const { importItems, urlItems } = parserOptions ;
128+ const { importItems } = parserOptions ;
129129
130130 // Run other loader (`postcss-loader`, `sass-loader` and etc) for importing CSS
131131 const importUrlPrefix = getImportPrefix ( this , importLoaders ) ;
@@ -206,40 +206,40 @@ module.exports = function loader(content, map) {
206206 // helper for ensuring valid CSS strings from requires
207207 let urlEscapeHelperCode = '' ;
208208
209- if ( resolveUrl && urlItems && urlItems . length > 0 ) {
210- urlEscapeHelperCode = `var escape = require(${ stringifyRequest (
211- this ,
212- require . resolve ( './runtime/escape.js' )
213- ) } );\n`;
214-
215- cssAsString = cssAsString . replace (
216- placholderRegExps . urlItemG ,
217- ( item ) => {
218- const match = placholderRegExps . urlItem . exec ( item ) ;
219- const idx = Number ( match [ 1 ] ) ;
220-
221- if ( ! urlItems [ idx ] ) {
222- return item ;
223- }
224-
225- const urlItem = urlItems [ idx ] ;
226- const { url } = urlItem ;
227- // Remove `#hash` and `?#hash` from `require`
228- const [ normalizedUrl , singleQuery , hashValue ] = url . split ( / ( \? ) ? # / ) ;
229- const hash =
230- singleQuery || hashValue
231- ? `"${ singleQuery ? '?' : '' } ${
232- hashValue ? `#${ hashValue } ` : ''
233- } "`
234- : '' ;
235-
236- return `" + escape(require(${ stringifyRequest (
209+ messages
210+ . filter ( ( message ) => message . type === 'url' && resolveUrl )
211+ . forEach ( ( message ) => {
212+ if ( ! urlEscapeHelperCode ) {
213+ urlEscapeHelperCode = `var escape = require(${ stringifyRequest (
237214 this ,
238- normalizedUrl
239- ) } )${ hash ? ` + ${ hash } ` : '' } ) + " `;
215+ require . resolve ( './runtime/escape.js' )
216+ ) } );\n `;
240217 }
241- ) ;
242- }
218+
219+ const { item } = message ;
220+ const { url, placeholder } = item ;
221+
222+ cssAsString = cssAsString . replace (
223+ new RegExp ( placeholder , 'g' ) ,
224+ ( ) => {
225+ // Remove `#hash` and `?#hash` from `require`
226+ const [ normalizedUrl , singleQuery , hashValue ] = url . split (
227+ / ( \? ) ? # /
228+ ) ;
229+ const hash =
230+ singleQuery || hashValue
231+ ? `"${ singleQuery ? '?' : '' } ${
232+ hashValue ? `#${ hashValue } ` : ''
233+ } "`
234+ : '' ;
235+
236+ return `" + escape(require(${ stringifyRequest (
237+ this ,
238+ normalizedUrl
239+ ) } )${ hash ? ` + ${ hash } ` : '' } ) + "`;
240+ }
241+ ) ;
242+ } ) ;
243243
244244 if ( exportCode ) {
245245 exportCode = `exports.locals = ${ exportCode } ;` ;
0 commit comments