vite-plugin-app-loading
v0.3.0
Published
[![NPM version](https://img.shields.io/npm/v/vite-plugin-app-loading?color=a1b858&label=)](https://www.npmjs.com/package/vite-plugin-app-loading)
Downloads
147
Readme
vite-plugin-app-loading
English | 中文
Add a loading animation to your Vue app.
Installation
npm i vite-plugin-app-loading -D
Usage
// vite.config.ts
import AppLoading from 'vite-plugin-app-loading'
export default defineConfig({
plugins: [
AppLoading(),
],
})
Hide the loading animation at the right time:
// src/main.ts
import { loadingFadeOut } from 'virtual:app-loading'
loadingFadeOut()
Types
There are two ways of telling typescript about the types of the virtual import:
In your
global.d.ts
file add the following line:/// <reference types="vite-plugin-app-loading/client" />
In your
tsconfig.json
add the following to your compilerOptions.types array:{ // ... "compilerOptions": { // ... "types": [ "vite-plugin-app-loading/client" ] } }
Custom animations
Create a loading.html
file at the root directory:
<style>
.loader {
font-weight: bold;
font-family: sans-serif;
font-size: 30px;
animation: l1 1s linear infinite alternate;
}
.loader:before {
content:"Loading..."
}
@keyframes l1 {to{opacity: 0}}
</style>
<div class="loader"></div>
// vite.config.ts
import AppLoading from 'vite-plugin-app-loading'
export default defineConfig({
plugins: [
AppLoading('loading.html'),
],
})
[!TIP] You can find inspiration from the following websites, which all provide CSS-only loading animations that are perfect for use with this plugin.
Example
Thanks
Thanks to vue-vben-admin for the inspiration.