Skip to content

Commit 53e113e

Browse files
committed
refactor: default entry name should be index
1 parent 3da5bec commit 53e113e

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

packages/runtime/plugin-i18n/src/runtime/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { MAIN_ENTRY_NAME } from '@modern-js/utils/universal/constants';
2-
3-
export const getEntryPath = (entryName: string = MAIN_ENTRY_NAME) => {
4-
return entryName === MAIN_ENTRY_NAME ? '' : `/${entryName}`;
1+
export const getEntryPath = (entryName?: string): string => {
2+
if (typeof window !== 'undefined' && (window as any).__MODERN_JS_BASE_NAME) {
3+
return (window as any).__MODERN_JS_BASE_NAME;
4+
}
5+
return '';
56
};
7+
68
/**
79
* Helper function to get language from current pathname
810
* @param pathname - The current pathname

packages/solutions/app-tools/src/builder/shared/builderPlugins/adapterHtml.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import type {
66
RsbuildPlugin,
77
RspackChain,
88
} from '@rsbuild/core';
9-
import type { HtmlUserConfig } from '../../../types/config/html';
109
import { BottomTemplatePlugin } from '../bundlerPlugins';
1110
import type { BuilderOptions } from '../types';
1211

1312
const createVirtualModule = (content: string) =>
14-
`data:text/javascript,${content}`;
13+
`data:text/javascript;charset=utf-8,${encodeURIComponent(content)}`;
1514

1615
export 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 */
5890
function applyBottomHtmlPlugin({
5991
chain,

packages/solutions/app-tools/src/config/default.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { MAIN_ENTRY_NAME } from '@modern-js/utils';
21
import type { AppUserConfig } from '../types';
32
import type { AppToolsContext } from '../types/plugin';
43
import { getAutoInjectEnv } from '../utils/env';
@@ -37,7 +36,7 @@ export function createDefaultConfig(
3736
alias: Record<string, string>;
3837
} = {
3938
entries: undefined,
40-
mainEntryName: MAIN_ENTRY_NAME,
39+
mainEntryName: 'index',
4140
enableAsyncEntry: false,
4241
disableDefaultEntries: false,
4342
entriesDir: './src',

0 commit comments

Comments
 (0)