vite-ssg-optimized 0.28.0-optimized.1 → 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 { createSSRApp, createApp } from 'vue';
4
- import { C as ClientOnly, d as documentReady } from '../shared/vite-ssg-optimized.ETIvV-80.mjs';
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 = !import.meta.env.SSR;
16
+ const isClient = !importMetaEnv.SSR;
16
17
  const isHydrationMode = options?.hydration || isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
17
- const app = import.meta.env.SSR || isHydrationMode ? createSSRApp(App) : createApp(App);
18
+ const app = isClient && !isHydrationMode ? createApp(App) : createSSRApp(App);
18
19
  let head;
19
20
  if (useHead) {
20
- app.use(head = import.meta.env.SSR ? createHead() : createHead$1());
21
+ app.use(head = importMetaEnv.SSR ? createHead() : createHead$1());
21
22
  }
22
23
  const appRenderCallbacks = [];
23
- const onSSRAppRendered = import.meta.env.SSR ? (cb) => appRenderCallbacks.push(cb) : () => {
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: !import.meta.env.SSR,
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 (!import.meta.env.SSR) {
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 (!import.meta.env.SSR) {
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.ETIvV-80.mjs';
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 = !import.meta.env.SSR;
17
+ const isClient = !importMetaEnv.SSR;
17
18
  const isHydrationMode = options?.hydration || isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
18
- const app = import.meta.env.SSR || isHydrationMode ? createApp(App) : createSSRApp(App);
19
+ const app = isClient && !isHydrationMode ? createApp(App) : createSSRApp(App);
19
20
  let head;
20
21
  if (useHead) {
21
- app.use(head = import.meta.env.SSR ? createHead() : createHead$1());
22
+ app.use(head = importMetaEnv.SSR ? createHead() : createHead$1());
22
23
  }
23
24
  const router = createRouter({
24
- history: import.meta.env.SSR ? createMemoryHistory(routerOptions.base) : createWebHistory(routerOptions.base),
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 = import.meta.env.SSR ? (cb) => appRenderCallbacks.push(cb) : () => {
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: !import.meta.env.SSR,
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 (!import.meta.env.SSR) {
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 (import.meta.env.SSR) {
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 (!import.meta.env.SSR) {
77
+ if (!importMetaEnv.SSR) {
77
78
  (async () => {
78
79
  const { app, router } = await createApp$1();
79
80
  await router.isReady();
package/dist/node/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import process from 'node:process';
2
2
  import { gray, bold, red } from 'ansis';
3
3
  import { cac } from 'cac';
4
- import { b as build } from '../shared/vite-ssg-optimized.BfxECNw7.mjs';
4
+ import { b as build } from '../shared/vite-ssg-optimized.PPG64DEt.mjs';
5
5
  import '@unhead/ssr';
6
6
  import 'html5parser';
7
7
  import 'node:worker_threads';
@@ -12,7 +12,7 @@ import 'node:url';
12
12
  import 'vite';
13
13
  import '../shared/vite-ssg-optimized.C6pK7rvr.mjs';
14
14
 
15
- const cli = cac("vite-ssg");
15
+ const cli = cac("vite-ssg-optimized");
16
16
  cli.command("build", "Build SSG").option("--script <script>", "Rewrites script loading timing").option("--mock", "Mock browser globals (window, document, etc.) for SSG").option("--mode <mode>", "Specify the mode the Vite process is running in").option("--config, -c <config>", "The vite config file to use").option("--base, -b <base>", "The base path to render").option("--skip-build", "Skip build if already have build in ssg-out dir").action(async (args) => {
17
17
  const { config: configFile = void 0, ...ssgOptions } = args;
18
18
  if (args.script && !["sync", "async", "defer", "async defer"].includes(args.script)) {
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as build } from './shared/vite-ssg-optimized.BfxECNw7.mjs';
1
+ export { b as build } from './shared/vite-ssg-optimized.PPG64DEt.mjs';
2
2
  import '@unhead/ssr';
3
3
  import 'html5parser';
4
4
  import 'node:worker_threads';
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { workerData, parentPort } from 'node:worker_threads';
3
- import { p as plainify, a as buildServer, c as buildClient, e as executeTaskFn } from './vite-ssg-optimized.BfxECNw7.mjs';
3
+ import { p as plainify, a as buildServer, c as buildClient, e as executeTaskFn } from './vite-ssg-optimized.PPG64DEt.mjs';
4
4
  import { red, gray, blue } from 'ansis';
5
5
  import { resolveConfig } from 'vite';
6
6
  import '@unhead/ssr';
@@ -21,4 +21,10 @@ const ClientOnly = defineComponent({
21
21
  }
22
22
  });
23
23
 
24
- export { ClientOnly as C, documentReady as d };
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 };
@@ -1158,7 +1158,7 @@ async function buildServer(config, viteConfig, { ssrEntry, ssgOut, mock }) {
1158
1158
  },
1159
1159
  mode: config.mode,
1160
1160
  ssr: {
1161
- noExternal: ["vite-ssg"]
1161
+ noExternal: ["vite-ssg-optimized"]
1162
1162
  }
1163
1163
  }));
1164
1164
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-ssg-optimized",
3
3
  "type": "module",
4
- "version": "0.28.0-optimized.1",
4
+ "version": "0.28.0-optimized.3",
5
5
  "description": "Server-side generation for Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -71,7 +71,7 @@
71
71
  }
72
72
  },
73
73
  "dependencies": {
74
- "@unhead/ssr": "~1.11.13",
74
+ "@unhead/ssr": "~2.0.11",
75
75
  "@unhead/vue": "^2.0.11",
76
76
  "ansis": "^4.1.0",
77
77
  "cac": "^6.7.14",