chore: update fixture
This commit is contained in:
11
fixtures/vitesse/src/modules/README.md
Normal file
11
fixtures/vitesse/src/modules/README.md
Normal 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
|
||||
}
|
||||
```
|
25
fixtures/vitesse/src/modules/i18n.ts
Normal file
25
fixtures/vitesse/src/modules/i18n.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import { type UserModule } from '~/types'
|
||||
|
||||
// Import i18n resources
|
||||
// https://vitejs.dev/guide/features.html#glob-import
|
||||
//
|
||||
// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
|
||||
const messages = Object.fromEntries(
|
||||
Object.entries(
|
||||
import.meta.glob<{ default: any }>('../../locales/*.y(a)?ml', { eager: true }))
|
||||
.map(([key, value]) => {
|
||||
const yaml = key.endsWith('.yaml')
|
||||
return [key.slice(14, yaml ? -5 : -4), value.default]
|
||||
}),
|
||||
)
|
||||
|
||||
export const install: UserModule = ({ app }) => {
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: 'en',
|
||||
messages,
|
||||
})
|
||||
|
||||
app.use(i18n)
|
||||
}
|
12
fixtures/vitesse/src/modules/nprogress.ts
Normal file
12
fixtures/vitesse/src/modules/nprogress.ts
Normal 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
fixtures/vitesse/src/modules/pinia.ts
Normal file
17
fixtures/vitesse/src/modules/pinia.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { createPinia } from 'pinia'
|
||||
import { type UserModule } from '~/types'
|
||||
|
||||
// Setup Pinia
|
||||
// https://pinia.vuejs.org/
|
||||
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
fixtures/vitesse/src/modules/pwa.ts
Normal file
12
fixtures/vitesse/src/modules/pwa.ts
Normal 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 })
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user