@@ -125,7 +125,7 @@ module.exports = function loader(content, map) {
125
125
126
126
const messages = result . messages || [ ] ;
127
127
const { camelCase, exportOnlyLocals, importLoaders } = options ;
128
- const { importItems, urlItems } = parserOptions ;
128
+ const { importItems } = parserOptions ;
129
129
130
130
// Run other loader (`postcss-loader`, `sass-loader` and etc) for importing CSS
131
131
const importUrlPrefix = getImportPrefix ( this , importLoaders ) ;
@@ -206,40 +206,40 @@ module.exports = function loader(content, map) {
206
206
// helper for ensuring valid CSS strings from requires
207
207
let urlEscapeHelperCode = '' ;
208
208
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 (
237
214
this ,
238
- normalizedUrl
239
- ) } )${ hash ? ` + ${ hash } ` : '' } ) + " `;
215
+ require . resolve ( './runtime/escape.js' )
216
+ ) } );\n `;
240
217
}
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
+ } ) ;
243
243
244
244
if ( exportCode ) {
245
245
exportCode = `exports.locals = ${ exportCode } ;` ;
0 commit comments