feat: init hoppscotch-embed package
This commit is contained in:
11
packages/hoppscotch-embed/src/modules/README.md
Normal file
11
packages/hoppscotch-embed/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 { UserModule } from '~/types'
|
||||
|
||||
export const install: UserModule = ({ app, router, isClient }) => {
|
||||
// do something
|
||||
}
|
||||
```
|
||||
25
packages/hoppscotch-embed/src/modules/i18n.ts
Normal file
25
packages/hoppscotch-embed/src/modules/i18n.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createI18n } from "vue-i18n"
|
||||
import { 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.globEager("../../locales/*.y(a)?ml"))
|
||||
.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)
|
||||
}
|
||||
9
packages/hoppscotch-embed/src/modules/nprogress.ts
Normal file
9
packages/hoppscotch-embed/src/modules/nprogress.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import NProgress from "nprogress"
|
||||
import { UserModule } from "~/types"
|
||||
|
||||
export const install: UserModule = ({ isClient, router }) => {
|
||||
if (isClient) {
|
||||
router.beforeEach(() => { NProgress.start() })
|
||||
router.afterEach(() => { NProgress.done() })
|
||||
}
|
||||
}
|
||||
17
packages/hoppscotch-embed/src/modules/pinia.ts
Normal file
17
packages/hoppscotch-embed/src/modules/pinia.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { createPinia } from "pinia"
|
||||
import { 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
packages/hoppscotch-embed/src/modules/pwa.ts
Normal file
12
packages/hoppscotch-embed/src/modules/pwa.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { 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