Out of the box spa application first screen loading placeholder plugin, avoid long time white screen before app launch.
npm i vite-plugin-spa-loading -D
# yarn
yarn add vite-plugin-spa-loading -D
# pnpm
pnpm add vite-plugin-spa-loading -D
Add spaLoading plugin to vite.config.js / vite.config.ts and configure it:
// vite.config.js / vite.config.ts
import { spaLoading } from 'vite-plugin-spa-loading'
export default {
plugins: [spaLoading()]
}
import { spaLoading } from 'vite-plugin-spa-loading'
export default {
plugins: [
spaLoading('text', {
tipText: 'The loading text...'
})
]
}
import { spaLoading } from 'vite-plugin-spa-loading'
export default {
plugins: [
spaLoading('svg', {
path: 'xxx/loading.svg'
// or
// content: '<svg>....</svg>'
})
]
}
import { spaLoading } from 'vite-plugin-spa-loading'
export default {
plugins: [
spaLoading('img', {
src: 'xxx/loading.gif'
})
]
}
Property Name | Type | Description | Default Value |
---|---|---|---|
rootElementId | string | The ID of the element where the app will be mounted. | - |
devEnable | boolean | Whether to enable development environment. | false |
css | string | Custom CSS styles. | - |
cssPath | string | External CSS file path. | - |
tipText | string | The loading placeholder text. | "Loading..." |
debounce | number | Debounce duration to avoid blinking of the loading animation in good network conditions. | - |
error.tip | string | The error message text. | - |
error.detail | boolean | Whether to show the error details. | - |
error.handler | Function | Error handling function that accepts an array of strings as a parameter. | - |
Image
interface extends BaseOptions
and adds the following properties:
Property Name | Type | Description | Default Value |
---|---|---|---|
src | string | Path to the image file or base64 encoded string. | - |
_Svg
interface extends BaseOptions
and adds the following properties:
Property Name | Type | Description | Default Value |
---|---|---|---|
content | string | SVG content string. | - |
or
Property Name | Type | Description | Default Value |
---|---|---|---|
path | string | SVG file path. | - |