@@ -244,8 +244,6 @@ const plugin = (options = {}) => {
244
244
const imports = new Map ( ) ;
245
245
const replacements = new Map ( ) ;
246
246
247
- let hasUrlImportHelper = false ;
248
-
249
247
for ( const parsedResult of parsedResults ) {
250
248
const { url, isStringValue } = parsedResult . rule ;
251
249
@@ -261,34 +259,21 @@ const plugin = (options = {}) => {
261
259
262
260
normalizedUrl = normalizeUrl ( normalizedUrl , isStringValue ) ;
263
261
264
- const processUrl = await options . filter ( normalizedUrl ) ;
265
- if ( ! processUrl ) {
266
- // eslint-disable-next-line no-continue
267
- continue ;
268
- }
269
-
270
- if ( ! hasUrlImportHelper ) {
271
- options . imports . push ( {
272
- importName : "___CSS_LOADER_GET_URL_IMPORT___" ,
273
- url : options . urlHandler (
274
- require . resolve ( "../runtime/getUrl.js" )
275
- ) ,
276
- index : - 1 ,
277
- } ) ;
278
-
279
- hasUrlImportHelper = true ;
280
- }
262
+ tasks . push (
263
+ ( async ( ) => {
264
+ const processUrl = await options . filter ( normalizedUrl ) ;
265
+ if ( ! processUrl ) {
266
+ return null ;
267
+ }
281
268
282
- const splittedUrl = normalizedUrl . split ( / ( \? ) ? # / ) ;
283
- const [ pathname , query , hashOrQuery ] = splittedUrl ;
269
+ const splittedUrl = normalizedUrl . split ( / ( \? ) ? # / ) ;
270
+ const [ pathname , query , hashOrQuery ] = splittedUrl ;
284
271
285
- let hash = query ? "?" : "" ;
286
- hash += hashOrQuery ? `#${ hashOrQuery } ` : "" ;
272
+ let hash = query ? "?" : "" ;
273
+ hash += hashOrQuery ? `#${ hashOrQuery } ` : "" ;
287
274
288
- const request = requestify ( pathname , options . rootContext ) ;
275
+ const request = requestify ( pathname , options . rootContext ) ;
289
276
290
- tasks . push (
291
- ( async ( ) => {
292
277
const { resolver, context } = options ;
293
278
const resolvedUrl = await resolveRequests ( resolver , context , [
294
279
...new Set ( [ request , normalizedUrl ] ) ,
@@ -301,13 +286,34 @@ const plugin = (options = {}) => {
301
286
302
287
const results = await Promise . all ( tasks ) ;
303
288
289
+ let hasUrlImportHelper = false ;
290
+
304
291
for ( let index = 0 ; index <= results . length - 1 ; index ++ ) {
292
+ const item = results [ index ] ;
293
+
294
+ if ( item === null ) {
295
+ // eslint-disable-next-line no-continue
296
+ continue ;
297
+ }
298
+
299
+ if ( ! hasUrlImportHelper ) {
300
+ options . imports . push ( {
301
+ importName : "___CSS_LOADER_GET_URL_IMPORT___" ,
302
+ url : options . urlHandler (
303
+ require . resolve ( "../runtime/getUrl.js" )
304
+ ) ,
305
+ index : - 1 ,
306
+ } ) ;
307
+
308
+ hasUrlImportHelper = true ;
309
+ }
310
+
305
311
const {
306
312
url,
307
313
prefix,
308
314
hash,
309
315
parsedResult : { node, rule, parsed } ,
310
- } = results [ index ] ;
316
+ } = item ;
311
317
const newUrl = prefix ? `${ prefix } !${ url } ` : url ;
312
318
const importKey = newUrl ;
313
319
let importName = imports . get ( importKey ) ;
0 commit comments