@@ -12,6 +12,7 @@ type Outputs = {
1212 fixture : string ;
1313 runtime : string ;
1414 vendor : string ;
15+ css ?: string ;
1516} ;
1617
1718type CompilationResult = {
@@ -22,6 +23,10 @@ type CompilationResult = {
2223} ;
2324
2425const uniqueName = 'ReactRefreshLibrary' ;
26+ const readOutput = ( fixturePath : string , file : string ) =>
27+ fs . existsSync ( path . join ( fixturePath , 'dist' , file ) )
28+ ? fs . readFileSync ( path . join ( fixturePath , 'dist' , file ) , 'utf-8' )
29+ : '' ;
2530
2631const compileWithReactRefresh = (
2732 fixturePath : string ,
@@ -32,7 +37,9 @@ const compileWithReactRefresh = (
3237 const cjsEntry = path . join ( fixturePath , 'index.js' ) ;
3338 const ctsEntry = path . join ( fixturePath , 'index.cjs' ) ;
3439 const mjsEntry = path . join ( fixturePath , 'index.mjs' ) ;
35- const customLoader = path . join ( fixturePath , 'loader.cjs' ) ;
40+ const customLoader = fs . existsSync ( path . join ( fixturePath , 'loader.cjs' ) )
41+ ? path . join ( fixturePath , 'loader.cjs' )
42+ : path . join ( import . meta. dirname , 'fixtures/loader/loader.cjs' ) ;
3643 const entry = fs . existsSync ( cjsEntry )
3744 ? cjsEntry
3845 : fs . existsSync ( ctsEntry )
@@ -52,6 +59,14 @@ const compileWithReactRefresh = (
5259 uniqueName,
5360 assetModuleFilename : '[name][ext]' ,
5461 } ,
62+ module : {
63+ rules : [
64+ {
65+ test : / \. c s s $ / ,
66+ type : 'css/auto' ,
67+ } ,
68+ ] ,
69+ } ,
5570 resolveLoader : {
5671 alias : {
5772 'custom-react-refresh-loader' : customLoader ,
@@ -112,22 +127,11 @@ const compileWithReactRefresh = (
112127 error,
113128 stats,
114129 outputs : {
115- reactRefresh : fs . readFileSync (
116- path . join ( fixturePath , 'dist' , 'react-refresh.js' ) ,
117- 'utf-8' ,
118- ) ,
119- fixture : fs . readFileSync (
120- path . join ( fixturePath , 'dist' , 'fixture.js' ) ,
121- 'utf-8' ,
122- ) ,
123- runtime : fs . readFileSync (
124- path . join ( fixturePath , 'dist' , 'runtime.js' ) ,
125- 'utf-8' ,
126- ) ,
127- vendor : fs . readFileSync (
128- path . join ( fixturePath , 'dist' , 'vendor.js' ) ,
129- 'utf-8' ,
130- ) ,
130+ reactRefresh : readOutput ( fixturePath , 'react-refresh.js' ) ,
131+ fixture : readOutput ( fixturePath , 'fixture.js' ) ,
132+ runtime : readOutput ( fixturePath , 'runtime.js' ) ,
133+ vendor : readOutput ( fixturePath , 'vendor.js' ) ,
134+ css : readOutput ( fixturePath , 'fixture.css' ) || undefined ,
131135 } ,
132136 plugin,
133137 } ) ;
@@ -301,4 +305,19 @@ describe('react-refresh-rspack-plugin', () => {
301305 expect ( fixture ) . toContain ( 'TEST_LOADER' ) ;
302306 expect ( fixture ) . not . toContain ( 'function $RefreshReg$' ) ;
303307 } ) ;
308+
309+ it ( 'should keep the default extension filter when include targets a directory' , async ( ) => {
310+ const {
311+ outputs : { fixture, css } ,
312+ } = await compileWithReactRefresh (
313+ path . join ( import . meta. dirname , 'fixtures/include' ) ,
314+ {
315+ include : path . join ( import . meta. dirname , 'fixtures/include' ) ,
316+ reactRefreshLoader : 'custom-react-refresh-loader' ,
317+ } ,
318+ ) ;
319+ expect ( fixture ) . toContain ( 'TEST_LOADER' ) ;
320+ expect ( css ) . toBeDefined ( ) ;
321+ expect ( css ) . not . toContain ( 'TEST_LOADER' ) ;
322+ } ) ;
304323} ) ;
0 commit comments