@@ -14,13 +14,19 @@ export const rsbuildPluginDocVM = async ({
1414 pageData : PageData | null ;
1515 searchIndex : Record < string , string > | null ;
1616 indexHashByGroup : Record < string , string > | null ;
17- } = { pageData : null , searchIndex : null , indexHashByGroup : null } ;
17+ filepaths : string [ ] ;
18+ } = {
19+ pageData : null ,
20+ searchIndex : null ,
21+ indexHashByGroup : null ,
22+ filepaths : [ ] ,
23+ } ;
1824 const searchIndexRsbuildPlugin : RsbuildPlugin = {
1925 name : 'rsbuild-plugin-searchIndex' ,
2026 async setup ( api ) {
2127 api . modifyBundlerChain ( async bundlerChain => {
2228 const alias = bundlerChain . resolve . alias . entries ( ) ;
23- const { pageData, indexHashByGroup, searchIndex } =
29+ const { pageData, indexHashByGroup, searchIndex, filepaths } =
2430 await createPageData ( {
2531 config,
2632 alias : alias as Record < string , string > ,
@@ -32,6 +38,8 @@ export const rsbuildPluginDocVM = async ({
3238 ref . pageData = pageData ;
3339 ref . searchIndex = searchIndex ;
3440 ref . indexHashByGroup = indexHashByGroup ;
41+ ref . filepaths = filepaths ;
42+
3543 api . processAssets (
3644 { stage : 'report' , environments : [ 'web' ] } ,
3745 ( { compilation, compiler } ) => {
@@ -54,10 +62,16 @@ export const rsbuildPluginDocVM = async ({
5462 pluginVirtualModule ( {
5563 tempDir : '.rspress' ,
5664 virtualModules : {
57- [ RuntimeModuleID . PageData ] : ( ) =>
58- `export default ${ JSON . stringify ( ref . pageData , null , 2 ) } ` ,
59- [ RuntimeModuleID . SearchIndexHash ] : ( ) =>
60- `export default ${ JSON . stringify ( ref . indexHashByGroup , null , 2 ) } ` ,
65+ [ RuntimeModuleID . PageData ] : async ( { addDependency } ) => {
66+ // TODO: support hmr
67+ // This place needs to obtain the specific file that has been modified and update the file information.
68+ for ( const file of ref . filepaths ) {
69+ addDependency ( file ) ;
70+ }
71+
72+ return `export const pageData = ${ JSON . stringify ( ref . pageData , null , 2 ) } ;
73+ export const searchIndexHash = ${ JSON . stringify ( ref . indexHashByGroup , null , 2 ) } ;` ;
74+ } ,
6175 } ,
6276 } ) ,
6377 ] ;
0 commit comments