@@ -244,8 +244,6 @@ const plugin = (options = {}) => {
244244 const imports = new Map ( ) ;
245245 const replacements = new Map ( ) ;
246246
247- let hasUrlImportHelper = false ;
248-
249247 for ( const parsedResult of parsedResults ) {
250248 const { url, isStringValue } = parsedResult . rule ;
251249
@@ -261,33 +259,21 @@ const plugin = (options = {}) => {
261259
262260 normalizedUrl = normalizeUrl ( normalizedUrl , isStringValue ) ;
263261
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+ }
280268
281- const splittedUrl = normalizedUrl . split ( / ( \? ) ? # / ) ;
282- const [ pathname , query , hashOrQuery ] = splittedUrl ;
269+ const splittedUrl = normalizedUrl . split ( / ( \? ) ? # / ) ;
270+ const [ pathname , query , hashOrQuery ] = splittedUrl ;
283271
284- let hash = query ? "?" : "" ;
285- hash += hashOrQuery ? `#${ hashOrQuery } ` : "" ;
272+ let hash = query ? "?" : "" ;
273+ hash += hashOrQuery ? `#${ hashOrQuery } ` : "" ;
286274
287- const request = requestify ( pathname , options . rootContext ) ;
275+ const request = requestify ( pathname , options . rootContext ) ;
288276
289- tasks . push (
290- ( async ( ) => {
291277 const { resolver, context } = options ;
292278 const resolvedUrl = await resolveRequests ( resolver , context , [
293279 ...new Set ( [ request , normalizedUrl ] ) ,
@@ -300,13 +286,34 @@ const plugin = (options = {}) => {
300286
301287 const results = await Promise . all ( tasks ) ;
302288
289+ let hasUrlImportHelper = false ;
290+
303291 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+
304311 const {
305312 url,
306313 prefix,
307314 hash,
308315 parsedResult : { node, rule, parsed } ,
309- } = results [ index ] ;
316+ } = item ;
310317 const newUrl = prefix ? `${ prefix } !${ url } ` : url ;
311318 const importKey = newUrl ;
312319 let importName = imports . get ( importKey ) ;
0 commit comments