init: basic structure

This commit is contained in:
YunYouJun
2022-04-13 22:41:22 +08:00
parent f77549b1cd
commit c355d51874
50 changed files with 7682 additions and 0 deletions

11
src/modules/README.md Normal file
View File

@@ -0,0 +1,11 @@
## Modules
A custom user module system. Place a `.ts` file with the following template, it will be installed automatically.
```ts
import { type UserModule } from '~/types'
export const install: UserModule = ({ app, router, isClient }) => {
// do something
}
```

12
src/modules/nprogress.ts Normal file
View File

@@ -0,0 +1,12 @@
import NProgress from 'nprogress'
import { type UserModule } from '~/types'
export const install: UserModule = ({ isClient, router }) => {
if (isClient) {
router.beforeEach((to, from) => {
if (to.path !== from.path)
NProgress.start()
})
router.afterEach(() => { NProgress.done() })
}
}

17
src/modules/pinia.ts Normal file
View File

@@ -0,0 +1,17 @@
import { createPinia } from 'pinia'
import { type UserModule } from '~/types'
// Setup Pinia
// https://pinia.esm.dev/
export const install: UserModule = ({ isClient, initialState, app }) => {
const pinia = createPinia()
app.use(pinia)
// Refer to
// https://github.com/antfu/vite-ssg/blob/main/README.md#state-serialization
// for other serialization strategies.
if (isClient)
pinia.state.value = (initialState.pinia) || {}
else
initialState.pinia = pinia.state.value
}

12
src/modules/pwa.ts Normal file
View File

@@ -0,0 +1,12 @@
import { type UserModule } from '~/types'
// https://github.com/antfu/vite-plugin-pwa#automatic-reload-when-new-content-available
export const install: UserModule = ({ isClient, router }) => {
if (!isClient)
return
router.isReady().then(async() => {
const { registerSW } = await import('virtual:pwa-register')
registerSW({ immediate: true })
})
}