@@ -366,7 +366,7 @@ describe('plugin-rspack-builtin-css', () => {
366366 ( rule . type === 'css/auto' && rule . parser ?. exportType !== 'text' ) ,
367367 ) ;
368368
369- expect ( styleRules ) . toHaveLength ( 2 ) ;
369+ expect ( styleRules ) . toHaveLength ( 3 ) ;
370370 expect (
371371 styleRules ?. every ( ( rule ) =>
372372 rule . use ?. some ( ( use ) =>
@@ -376,6 +376,45 @@ describe('plugin-rspack-builtin-css', () => {
376376 ) . toBe ( true ) ;
377377 } ) ;
378378
379+ it ( 'should add a CSS Modules oneOf rule for resource queries' , async ( ) => {
380+ const rsbuild = await createRsbuild ( {
381+ config : {
382+ plugins : [ pluginRspackBuiltinCss ( ) ] ,
383+ } ,
384+ } ) ;
385+ rstest . spyOn ( rsbuild . logger , 'warn' ) . mockImplementation ( ( ) => { } ) ;
386+
387+ const [ rspackConfig ] = await rsbuild . initConfigs ( ) ;
388+ const rules = matchRules ( rspackConfig , 'a.vue.css' ) ;
389+ const oneOf = ( rules [ 0 ] as { oneOf ?: Rspack . RuleSetRule [ ] } ) . oneOf ;
390+ const inlineRuleIndex = oneOf ?. findIndex (
391+ ( rule ) => String ( rule . resourceQuery ) === String ( / [ ? & ] i n l i n e (?: & | = | $ ) / ) ,
392+ ) ;
393+ const queryModuleRuleIndex = oneOf ?. findIndex (
394+ ( rule ) => String ( rule . resourceQuery ) === String ( / [ ? & ] m o d u l e (?: & | = | $ ) / ) ,
395+ ) ;
396+ const fallbackRuleIndex = oneOf ?. findIndex (
397+ ( rule ) => rule . type === 'css/auto' && ! rule . resourceQuery && ! rule . test ,
398+ ) ;
399+ const queryModuleRule = oneOf ?. [ queryModuleRuleIndex ?? - 1 ] ;
400+
401+ expect ( oneOf ?. [ inlineRuleIndex ?? - 1 ] ) . toMatchObject ( {
402+ parser : {
403+ exportType : 'text' ,
404+ } ,
405+ type : 'css/auto' ,
406+ } ) ;
407+ expect ( queryModuleRule ) . toMatchObject ( {
408+ sideEffects : true ,
409+ type : 'css/module' ,
410+ } ) ;
411+ expect (
412+ ( queryModuleRule ?. resourceQuery as RegExp ) . test ( '?vue&type=style&module=&lang=css' ) ,
413+ ) . toBe ( true ) ;
414+ expect ( inlineRuleIndex ) . toBeLessThan ( queryModuleRuleIndex ! ) ;
415+ expect ( queryModuleRuleIndex ) . toBeLessThan ( fallbackRuleIndex ! ) ;
416+ } ) ;
417+
379418 it ( 'should warn about unsupported CSS Modules options' , async ( ) => {
380419 const rsbuild = await createRsbuild ( {
381420 config : {
@@ -403,27 +442,6 @@ describe('plugin-rspack-builtin-css', () => {
403442 '`output.cssModules.exportGlobals` is not supported by `pluginRspackBuiltinCss`. The value will be ignored.' ,
404443 ) ;
405444 } ) ;
406-
407- it ( 'should warn when used with the Vue plugin' , async ( ) => {
408- const rsbuild = await createRsbuild ( {
409- config : {
410- plugins : [
411- {
412- name : 'rsbuild:vue' ,
413- setup ( ) { } ,
414- } ,
415- pluginRspackBuiltinCss ( ) ,
416- ] ,
417- } ,
418- } ) ;
419- const warn = rstest . spyOn ( rsbuild . logger , 'warn' ) . mockImplementation ( ( ) => { } ) ;
420-
421- await rsbuild . initConfigs ( ) ;
422-
423- expect ( warn ) . toHaveBeenCalledWith (
424- 'Vue SFC CSS Modules (`<style module>`) are not supported by `pluginRspackBuiltinCss`.' ,
425- ) ;
426- } ) ;
427445} ) ;
428446
429447describe ( 'plugin-css injectStyles' , ( ) => {
0 commit comments