-
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathmain.ts
More file actions
24 lines (21 loc) · 619 Bytes
/
main.ts
File metadata and controls
24 lines (21 loc) · 619 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { createPinia } from 'pinia'
import { ViteSSG } from 'vite-ssg/single-page'
import App from './App.vue'
import { useRootStore } from './store/root'
export const createApp = ViteSSG(
App,
({ app, initialState }) => {
const pinia = createPinia()
app.use(pinia)
if (import.meta.env.SSR) {
// this will be stringified and set to window.__INITIAL_STATE__
initialState.pinia = pinia.state.value
}
else {
// on the client side, we restore the state
pinia.state.value = initialState.pinia || {}
}
const store = useRootStore(pinia)
store.initialize()
},
)