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