mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-07 16:48:39 +08:00
修改全局loading消失时机
This commit is contained in:
+37
-27
@@ -124,34 +124,44 @@ export default function createVitePlugins(viteEnv, isBuild = false) {
|
||||
}
|
||||
})(),
|
||||
|
||||
{
|
||||
name: 'vite-plugin-loading',
|
||||
enforce: 'pre',
|
||||
transformIndexHtml: {
|
||||
handler: async html => html.replace(/<\/body>/, `${
|
||||
`<div data-app-loading>${await fs.readFileSync(path.resolve(process.cwd(), 'loading.html'), 'utf8')}</div>`
|
||||
}</body>`),
|
||||
order: 'pre',
|
||||
},
|
||||
transform: (code, id) => {
|
||||
if (/src\/main.ts$/.test(id)) {
|
||||
code = code.concat(`
|
||||
const loadingEl = document.querySelector('[data-app-loading]')
|
||||
if (loadingEl) {
|
||||
loadingEl.style['pointer-events'] = 'none'
|
||||
loadingEl.style.visibility = 'hidden'
|
||||
loadingEl.style.opacity = 0
|
||||
loadingEl.style.transition = 'all 0.5s ease-out'
|
||||
loadingEl.addEventListener('transitionend', () => loadingEl.remove(), { once: true })
|
||||
}
|
||||
`)
|
||||
return {
|
||||
code,
|
||||
map: null,
|
||||
(function () {
|
||||
const virtualModuleId = 'virtual:app-loading'
|
||||
const resolvedVirtualModuleId = `\0${virtualModuleId}`
|
||||
return {
|
||||
name: 'vite-plugin-loading',
|
||||
resolveId(id) {
|
||||
if (id === virtualModuleId) {
|
||||
return resolvedVirtualModuleId
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
load(id) {
|
||||
if (id === resolvedVirtualModuleId) {
|
||||
return {
|
||||
code: `
|
||||
export function loadingFadeOut() {
|
||||
const loadingEl = document.querySelector('[data-app-loading]')
|
||||
if (loadingEl) {
|
||||
loadingEl.style['pointer-events'] = 'none'
|
||||
loadingEl.style.visibility = 'hidden'
|
||||
loadingEl.style.opacity = 0
|
||||
loadingEl.style.transition = 'all 0.5s ease-out'
|
||||
loadingEl.addEventListener('transitionend', () => loadingEl.remove(), { once: true })
|
||||
}
|
||||
}
|
||||
`,
|
||||
map: null,
|
||||
}
|
||||
}
|
||||
},
|
||||
enforce: 'pre',
|
||||
transformIndexHtml: {
|
||||
handler: async html => html.replace(/<\/body>/, `${
|
||||
`<div data-app-loading>${await fs.readFileSync(path.resolve(process.cwd(), 'loading.html'), 'utf8')}</div>`
|
||||
}</body>`),
|
||||
order: 'pre',
|
||||
},
|
||||
}
|
||||
})(),
|
||||
|
||||
// https://github.com/unplugin/unplugin-turbo-console
|
||||
TurboConsole(),
|
||||
|
||||
Reference in New Issue
Block a user