feat(ui): change loader to mui-like style, and async load js and css (#250)

* fix (ui): async load js and css

currently, loader only appears when js and css load failed. this fix to show loading animation while js and css is loading.

* feat(ui): change loader to mui-like style
This commit is contained in:
Darren Yu 2025-04-24 08:04:00 +01:00 committed by GitHub
parent 9a41ebc845
commit 8bba067340
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 16 deletions

View File

@ -48,21 +48,35 @@
transform: scale(0.8);
animation: fadeIn 0.6s ease-out 0.3s forwards;
}
#app-loader .spinner::after {
content: "";
position: absolute;
top: -3px;
left: -3px;
width: 100%;
height: 100%;
border: 4px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top-color: var(--defaultThemeColor);
animation: spin 1s ease-in-out infinite;
#app-loader .spinner {
display: inline-block;
width: 40px;
height: 40px;
}
@keyframes spin {
to {
transform: rotate(360deg);
#app-loader .spinner svg {
display: block;
}
#app-loader .spinner .stroke {
stroke: var(--defaultThemeColor);
stroke-linecap: round;
animation: spinDash 1.4s ease-in-out infinite;
}
#app-loader .spinner .background {
stroke: rgba(0, 0, 0, 0.1)
}
@keyframes spinDash {
0% {
stroke-dasharray: 1px, 200px;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 100px, 200px;
stroke-dashoffset: -15px;
}
100% {
stroke-dasharray: 1px, 200px;
stroke-dashoffset: -126px;
}
}
@keyframes fadeIn {
@ -77,9 +91,14 @@
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="app-loader">
<div class="logo"></div>
<div class="spinner"></div>
<div class="spinner">
<svg viewBox="22 22 44 44">
<circle class="background" cx="44" cy="44" r="20" fill="none" stroke-width="4"></circle>
<circle class="stroke" cx="44" cy="44" r="20" fill="none" stroke-width="4"></circle>
</svg>
</div>
</div>
<script type="module" src="/src/main.tsx"></script>
<script async type="module" src="/src/main.tsx"></script>
<div id="root"></div>
<script>
document.addEventListener("DOMContentLoaded", function () {

View File

@ -37,6 +37,15 @@ export default defineConfig({
},
],
}),
{
name: "load-stylesheet-async",
transformIndexHtml(html) {
return html.replace(
/<link rel="stylesheet" crossorigin href="(.+?)">/g,
`<link rel="stylesheet" crossorigin href="$1" media="print" onload="this.media='all'">`
);
},
},
{
name: "generate-version",
async writeBundle(outputOptions) {