@@ -6,12 +6,11 @@ import type {
66 RsbuildPlugin ,
77 RspackChain ,
88} from '@rsbuild/core' ;
9- import type { HtmlUserConfig } from '../../../types/config/html' ;
109import { BottomTemplatePlugin } from '../bundlerPlugins' ;
1110import type { BuilderOptions } from '../types' ;
1211
1312const createVirtualModule = ( content : string ) =>
14- `data:text/javascript,${ content } ` ;
13+ `data:text/javascript;charset=utf-8 ,${ encodeURIComponent ( content ) } ` ;
1514
1615export const builderPluginAdapterHtml = (
1716 options : BuilderOptions ,
@@ -37,6 +36,11 @@ export const builderPluginAdapterHtml = (
3736 await injectAssetPrefix ( {
3837 chain,
3938 } ) ;
39+
40+ await injectEntryInfo ( {
41+ chain,
42+ options,
43+ } ) ;
4044 }
4145 } ,
4246 ) ;
@@ -54,6 +58,34 @@ async function injectAssetPrefix({ chain }: { chain: RspackChain }) {
5458 } ) ;
5559}
5660
61+ /**
62+ * Inject entry info (basename and entryName) for each entry
63+ */
64+ async function injectEntryInfo ( {
65+ chain,
66+ options,
67+ } : {
68+ chain : RspackChain ;
69+ options : BuilderOptions ;
70+ } ) {
71+ const entries = chain . entryPoints . entries ( ) || { } ;
72+ const entryNames = Object . keys ( entries ) ;
73+
74+ const serverRoutes = options . appContext . serverRoutes ;
75+
76+ entryNames . forEach ( entryName => {
77+ const route = serverRoutes . find ( route => route . entryName === entryName ) ;
78+ const basename = route ?. urlPath || `/${ entryName } ` ;
79+
80+ const entryInfoCode = [
81+ `window.__MODERN_JS_BASE_NAME = '${ basename } ';` ,
82+ `window.__MODERN_JS_ENTRY_NAME = '${ entryName } ';` ,
83+ ] . join ( '\n' ) ;
84+
85+ entries [ entryName ] . prepend ( createVirtualModule ( entryInfoCode ) ) ;
86+ } ) ;
87+ }
88+
5789/** inject bottom template */
5890function applyBottomHtmlPlugin ( {
5991 chain,
0 commit comments