perf: Improve the global loading display

This commit is contained in:
vben
2024-06-02 23:50:58 +08:00
parent e650a0b863
commit 77d40dc763
14 changed files with 111 additions and 57 deletions

View File

@@ -35,7 +35,7 @@ async function viteExtraAppConfigPlugin({
return {
async configResolved(config) {
publicPath = config.base;
publicPath = ensureTrailingSlash(config.base);
source = await getConfigSource();
},
async generateBundle() {
@@ -59,21 +59,13 @@ async function viteExtraAppConfigPlugin({
},
name: 'vite:extra-app-config',
async transformIndexHtml(html) {
publicPath = publicPath.endsWith('/') ? publicPath : `${publicPath}/`;
const hash = `v=${version}-${generatorContentHash(source, 8)}`;
const appConfigSrc = `${publicPath}${GLOBAL_CONFIG_FILE_NAME}?${hash}`;
return {
html,
tags: [
{
attrs: {
src: appConfigSrc,
},
tag: 'script',
},
],
tags: [{ attrs: { src: appConfigSrc }, tag: 'script' }],
};
},
};
@@ -94,4 +86,8 @@ async function getConfigSource() {
return source;
}
function ensureTrailingSlash(path: string) {
return path.endsWith('/') ? path : `${path}/`;
}
export { viteExtraAppConfigPlugin };