@@ -489,43 +489,58 @@ impl ModuleOptions {
489489 )
490490 } ;
491491 for ( key, rule) in webpack_loaders_options. rules . await ?. iter ( ) {
492- rules. push ( ModuleRule :: new (
493- RuleCondition :: All ( vec ! [
494- if key. starts_with( "#" ) {
495- // This is a custom marker requiring a corresponding condition entry
496- let conditions = ( * webpack_loaders_options. conditions. await ?)
497- . context(
498- "Expected a condition entry for the webpack loader rule \
499- matching {key}. Create a `conditions` mapping in your \
500- next.config.js",
501- ) ?
502- . await ?;
503-
504- let condition = conditions. get( key) . context(
505- "Expected a condition entry for the webpack loader rule matching \
506- {key}.",
507- ) ?;
508-
509- match & condition. path {
510- ConditionPath :: Glob ( glob) => RuleCondition :: ResourcePathGlob {
492+ let mut rule_conditions = Vec :: new ( ) ;
493+ if key. starts_with ( "#" ) {
494+ // This is a custom marker requiring a corresponding condition entry
495+ let conditions = ( * webpack_loaders_options. conditions . await ?)
496+ . context (
497+ "Expected a condition entry for the webpack loader rule matching \
498+ {key}. Create a `conditions` mapping in your next.config.js",
499+ ) ?
500+ . await ?;
501+
502+ let condition = conditions. get ( key) . context (
503+ "Expected a condition entry for the webpack loader rule matching {key}." ,
504+ ) ?;
505+
506+ let ConditionItem { path, content } = & condition;
507+
508+ match & path {
509+ Some ( ConditionPath :: Glob ( glob) ) => {
510+ if glob. contains ( '/' ) {
511+ rule_conditions. push ( RuleCondition :: ResourcePathGlob {
511512 base : execution_context. project_path ( ) . owned ( ) . await ?,
512513 glob : Glob :: new ( glob. clone ( ) ) . await ?,
513- } ,
514- ConditionPath :: Regex ( regex) => {
515- RuleCondition :: ResourcePathEsRegex ( regex. await ?)
516- }
517- }
518- } else if key. contains( '/' ) {
519- RuleCondition :: ResourcePathGlob {
520- base: execution_context. project_path( ) . owned( ) . await ?,
521- glob: Glob :: new( key. clone( ) ) . await ?,
514+ } ) ;
515+ } else {
516+ rule_conditions. push ( RuleCondition :: ResourceBasePathGlob (
517+ Glob :: new ( glob. clone ( ) ) . await ?,
518+ ) ) ;
522519 }
523- } else {
524- RuleCondition :: ResourceBasePathGlob ( Glob :: new( key. clone( ) ) . await ?)
525- } ,
526- RuleCondition :: not( RuleCondition :: ResourceIsVirtualSource ) ,
527- module_css_external_transform_conditions. clone( ) ,
528- ] ) ,
520+ }
521+ Some ( ConditionPath :: Regex ( regex) ) => {
522+ rule_conditions. push ( RuleCondition :: ResourcePathEsRegex ( regex. await ?) ) ;
523+ }
524+ None => { }
525+ }
526+ if let Some ( content) = content {
527+ rule_conditions. push ( RuleCondition :: ResourceContentEsRegex ( content. await ?) ) ;
528+ }
529+ } else if key. contains ( '/' ) {
530+ rule_conditions. push ( RuleCondition :: ResourcePathGlob {
531+ base : execution_context. project_path ( ) . owned ( ) . await ?,
532+ glob : Glob :: new ( key. clone ( ) ) . await ?,
533+ } ) ;
534+ } else {
535+ rule_conditions. push ( RuleCondition :: ResourceBasePathGlob (
536+ Glob :: new ( key. clone ( ) ) . await ?,
537+ ) ) ;
538+ } ;
539+ rule_conditions. push ( RuleCondition :: not ( RuleCondition :: ResourceIsVirtualSource ) ) ;
540+ rule_conditions. push ( module_css_external_transform_conditions. clone ( ) ) ;
541+
542+ rules. push ( ModuleRule :: new (
543+ RuleCondition :: All ( rule_conditions) ,
529544 vec ! [ ModuleRuleEffect :: SourceTransforms ( ResolvedVc :: cell( vec![
530545 ResolvedVc :: upcast(
531546 WebpackLoaders :: new(
0 commit comments