vite-ssg-optimized 0.28.0-optimized.2 → 0.28.0-optimized.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createHead as createHead$1 } from '@unhead/vue/client';
|
|
2
2
|
import { createHead } from '@unhead/vue/server';
|
|
3
|
-
import {
|
|
4
|
-
import { C as ClientOnly, d as documentReady } from '../shared/vite-ssg-optimized.
|
|
3
|
+
import { createApp, createSSRApp } from 'vue';
|
|
4
|
+
import { g as getImportMetaEnv, C as ClientOnly, d as documentReady } from '../shared/vite-ssg-optimized.D6MbDXbJ.mjs';
|
|
5
5
|
import { d as deserializeState } from '../shared/vite-ssg-optimized.C6pK7rvr.mjs';
|
|
6
6
|
|
|
7
7
|
function ViteSSG(App, fn, options) {
|
|
8
|
+
const importMetaEnv = getImportMetaEnv();
|
|
8
9
|
const {
|
|
9
10
|
transformState,
|
|
10
11
|
registerComponents = true,
|
|
@@ -12,15 +13,15 @@ function ViteSSG(App, fn, options) {
|
|
|
12
13
|
rootContainer = "#app"
|
|
13
14
|
} = options ?? {};
|
|
14
15
|
async function createApp$1() {
|
|
15
|
-
const isClient = !
|
|
16
|
+
const isClient = !importMetaEnv.SSR;
|
|
16
17
|
const isHydrationMode = options?.hydration || isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
|
|
17
|
-
const app =
|
|
18
|
+
const app = isClient && !isHydrationMode ? createApp(App) : createSSRApp(App);
|
|
18
19
|
let head;
|
|
19
20
|
if (useHead) {
|
|
20
|
-
app.use(head =
|
|
21
|
+
app.use(head = importMetaEnv.SSR ? createHead() : createHead$1());
|
|
21
22
|
}
|
|
22
23
|
const appRenderCallbacks = [];
|
|
23
|
-
const onSSRAppRendered =
|
|
24
|
+
const onSSRAppRendered = importMetaEnv.SSR ? (cb) => appRenderCallbacks.push(cb) : () => {
|
|
24
25
|
};
|
|
25
26
|
const triggerOnSSRAppRendered = () => {
|
|
26
27
|
return Promise.all(appRenderCallbacks.map((cb) => cb()));
|
|
@@ -28,7 +29,7 @@ function ViteSSG(App, fn, options) {
|
|
|
28
29
|
const context = {
|
|
29
30
|
app,
|
|
30
31
|
head,
|
|
31
|
-
isClient: !
|
|
32
|
+
isClient: !importMetaEnv.SSR,
|
|
32
33
|
router: void 0,
|
|
33
34
|
routes: void 0,
|
|
34
35
|
initialState: {},
|
|
@@ -38,7 +39,7 @@ function ViteSSG(App, fn, options) {
|
|
|
38
39
|
};
|
|
39
40
|
if (registerComponents)
|
|
40
41
|
app.component("ClientOnly", ClientOnly);
|
|
41
|
-
if (!
|
|
42
|
+
if (!importMetaEnv.SSR) {
|
|
42
43
|
await documentReady();
|
|
43
44
|
context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || deserializeState(window.__INITIAL_STATE__);
|
|
44
45
|
}
|
|
@@ -49,7 +50,7 @@ function ViteSSG(App, fn, options) {
|
|
|
49
50
|
initialState
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
if (!
|
|
53
|
+
if (!importMetaEnv.SSR) {
|
|
53
54
|
(async () => {
|
|
54
55
|
const { app } = await createApp$1();
|
|
55
56
|
app.mount(rootContainer, true);
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createHead as createHead$1 } from '@unhead/vue/client';
|
|
|
2
2
|
import { createHead } from '@unhead/vue/server';
|
|
3
3
|
import { createApp, createSSRApp } from 'vue';
|
|
4
4
|
import { createRouter, createMemoryHistory, createWebHistory } from 'vue-router';
|
|
5
|
-
import { C as ClientOnly, d as documentReady } from './shared/vite-ssg-optimized.
|
|
5
|
+
import { g as getImportMetaEnv, C as ClientOnly, d as documentReady } from './shared/vite-ssg-optimized.D6MbDXbJ.mjs';
|
|
6
6
|
import { d as deserializeState } from './shared/vite-ssg-optimized.C6pK7rvr.mjs';
|
|
7
7
|
|
|
8
8
|
function ViteSSG(App, routerOptions, fn, options) {
|
|
@@ -12,23 +12,24 @@ function ViteSSG(App, routerOptions, fn, options) {
|
|
|
12
12
|
useHead = true,
|
|
13
13
|
rootContainer = "#app"
|
|
14
14
|
} = options ?? {};
|
|
15
|
+
const importMetaEnv = getImportMetaEnv();
|
|
15
16
|
async function createApp$1(routePath) {
|
|
16
|
-
const isClient = !
|
|
17
|
+
const isClient = !importMetaEnv.SSR;
|
|
17
18
|
const isHydrationMode = options?.hydration || isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
|
|
18
|
-
const app =
|
|
19
|
+
const app = isClient && !isHydrationMode ? createApp(App) : createSSRApp(App);
|
|
19
20
|
let head;
|
|
20
21
|
if (useHead) {
|
|
21
|
-
app.use(head =
|
|
22
|
+
app.use(head = importMetaEnv.SSR ? createHead() : createHead$1());
|
|
22
23
|
}
|
|
23
24
|
const router = createRouter({
|
|
24
|
-
history:
|
|
25
|
+
history: importMetaEnv.SSR ? createMemoryHistory(routerOptions.base) : createWebHistory(routerOptions.base),
|
|
25
26
|
...routerOptions
|
|
26
27
|
});
|
|
27
28
|
const { routes } = routerOptions;
|
|
28
29
|
if (registerComponents)
|
|
29
30
|
app.component("ClientOnly", ClientOnly);
|
|
30
31
|
const appRenderCallbacks = [];
|
|
31
|
-
const onSSRAppRendered =
|
|
32
|
+
const onSSRAppRendered = importMetaEnv.SSR ? (cb) => appRenderCallbacks.push(cb) : () => {
|
|
32
33
|
};
|
|
33
34
|
const triggerOnSSRAppRendered = () => {
|
|
34
35
|
return Promise.all(appRenderCallbacks.map((cb) => cb()));
|
|
@@ -36,7 +37,7 @@ function ViteSSG(App, routerOptions, fn, options) {
|
|
|
36
37
|
const context = {
|
|
37
38
|
app,
|
|
38
39
|
head,
|
|
39
|
-
isClient: !
|
|
40
|
+
isClient: !importMetaEnv.SSR,
|
|
40
41
|
router,
|
|
41
42
|
routes,
|
|
42
43
|
onSSRAppRendered,
|
|
@@ -45,7 +46,7 @@ function ViteSSG(App, routerOptions, fn, options) {
|
|
|
45
46
|
transformState,
|
|
46
47
|
routePath
|
|
47
48
|
};
|
|
48
|
-
if (!
|
|
49
|
+
if (!importMetaEnv.SSR) {
|
|
49
50
|
await documentReady();
|
|
50
51
|
context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || deserializeState(window.__INITIAL_STATE__);
|
|
51
52
|
}
|
|
@@ -61,7 +62,7 @@ function ViteSSG(App, routerOptions, fn, options) {
|
|
|
61
62
|
}
|
|
62
63
|
next();
|
|
63
64
|
});
|
|
64
|
-
if (
|
|
65
|
+
if (importMetaEnv.SSR) {
|
|
65
66
|
const route = context.routePath ?? "/";
|
|
66
67
|
router.push(route);
|
|
67
68
|
await router.isReady();
|
|
@@ -73,7 +74,7 @@ function ViteSSG(App, routerOptions, fn, options) {
|
|
|
73
74
|
initialState
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
|
-
if (!
|
|
77
|
+
if (!importMetaEnv.SSR) {
|
|
77
78
|
(async () => {
|
|
78
79
|
const { app, router } = await createApp$1();
|
|
79
80
|
await router.isReady();
|
|
@@ -21,4 +21,10 @@ const ClientOnly = defineComponent({
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
function getImportMetaEnv() {
|
|
25
|
+
return "env" in import.meta ? import.meta.env : {
|
|
26
|
+
SSR: typeof setImmediate === "function" && "unref" in setTimeout(() => void 0)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { ClientOnly as C, documentReady as d, getImportMetaEnv as g };
|
package/package.json
CHANGED