vite-ssg-optimized 0.24.2-optimized.9 → 0.28.0-optimized.1

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.
Files changed (40) hide show
  1. package/README.md +51 -7
  2. package/dist/chunks/jsdomGlobal.mjs +10 -65
  3. package/dist/client/single-page.d.mts +3 -4
  4. package/dist/client/single-page.mjs +28 -17
  5. package/dist/index.d.mts +3 -4
  6. package/dist/index.mjs +20 -20
  7. package/dist/node/cli.mjs +25 -38
  8. package/dist/node.d.mts +8 -4
  9. package/dist/node.mjs +9 -8
  10. package/dist/shared/build.worker.d.mts +3 -15
  11. package/dist/shared/build.worker.mjs +67 -43
  12. package/dist/shared/{vite-ssg-optimized.15646db4.mjs → vite-ssg-optimized.BfxECNw7.mjs} +741 -652
  13. package/dist/shared/{vite-ssg-optimized.cf5cb4ee.d.mts → vite-ssg-optimized.C_FfKIMS.d.mts} +26 -23
  14. package/package.json +41 -57
  15. package/dist/chunks/jsdomGlobal.cjs +0 -91
  16. package/dist/client/single-page.cjs +0 -52
  17. package/dist/client/single-page.d.cts +0 -12
  18. package/dist/client/single-page.d.ts +0 -12
  19. package/dist/index.cjs +0 -88
  20. package/dist/index.d.cts +0 -12
  21. package/dist/index.d.ts +0 -12
  22. package/dist/node/cli.cjs +0 -52
  23. package/dist/node/cli.d.cts +0 -2
  24. package/dist/node/cli.d.ts +0 -2
  25. package/dist/node.cjs +0 -17
  26. package/dist/node.d.cts +0 -9
  27. package/dist/node.d.ts +0 -9
  28. package/dist/shared/build.worker.cjs +0 -105
  29. package/dist/shared/build.worker.d.cts +0 -30
  30. package/dist/shared/build.worker.d.ts +0 -30
  31. package/dist/shared/vite-ssg-optimized.0250a125.cjs +0 -27
  32. package/dist/shared/vite-ssg-optimized.12fd9d22.d.cts +0 -9
  33. package/dist/shared/vite-ssg-optimized.892682c8.d.mts +0 -9
  34. package/dist/shared/vite-ssg-optimized.950926bc.d.ts +0 -9
  35. package/dist/shared/vite-ssg-optimized.9966b43f.cjs +0 -1470
  36. package/dist/shared/vite-ssg-optimized.bee8a5a9.cjs +0 -37
  37. package/dist/shared/vite-ssg-optimized.cf5cb4ee.d.cts +0 -167
  38. package/dist/shared/vite-ssg-optimized.cf5cb4ee.d.ts +0 -167
  39. /package/dist/shared/{vite-ssg-optimized.579feabb.mjs → vite-ssg-optimized.C6pK7rvr.mjs} +0 -0
  40. /package/dist/shared/{vite-ssg-optimized.5912142e.mjs → vite-ssg-optimized.ETIvV-80.mjs} +0 -0
package/README.md CHANGED
@@ -1,11 +1,44 @@
1
- # Vite SSG
1
+ # Vite SSG Optimized
2
2
 
3
3
  Static-site generation for Vue 3 on Vite.
4
4
 
5
5
  [![NPM version](https://img.shields.io/npm/v/vite-ssg?color=a1b858)](https://www.npmjs.com/package/vite-ssg)
6
6
 
7
+ > ℹ️ **ESM-only from `v27.0.0` (CJS generation format also dropped).**
8
+ >
7
9
  > ℹ️ **Vite 2 is supported from `v0.2.x`, Vite 1's support is discontinued.**
8
10
 
11
+ > ℹ️ This is a fork from vite-ssg
12
+
13
+ ## Optimizations
14
+
15
+ * Replaced @unhead/dom by @unhead/ssr
16
+ * Used a custom injectInHtml instead of jsdom with is faster
17
+ * Added worker threads to avoid locking main event loop
18
+ * Avoid grow the number of tasks in queue when we have many routes
19
+ * Added teleport support, the original vite-ssg don't writes teleports to the final file causing SSR mismatches
20
+ * Detect if is in isHydrationMode by quering [data-server-rendered] on client
21
+ * Creates SSRApp or App accord with environment and hydration
22
+
23
+
24
+
25
+ #### Thread Workers
26
+
27
+ To configure `workerThreads` `ssgOptions.numberOfWorkers` in `vite.config.ts`
28
+
29
+ Each thread accept the `Math.ceil(concurrency / numberOfWorkers )` concurrent tasks at max.
30
+
31
+ ```ts
32
+ defineConfig({
33
+ ssgOptions: {
34
+ concurrency: 50,
35
+ numberOfWorkers: 5 // 5 is the default
36
+ }
37
+ })
38
+ ```
39
+
40
+
41
+
9
42
  ## Install
10
43
 
11
44
  > **This library requires Node.js version >= 14**
@@ -46,6 +79,17 @@ export const createApp = ViteSSG(
46
79
  )
47
80
  ```
48
81
 
82
+ ### How to allow Rollup tree-shake your client code
83
+
84
+ In order to allow Rollup tree-shake your client code at build time, you need to wrap your code using `import.meta.env.SSR`, that's, checking if the build is for the server: Rollup will remove the server code from the client build.
85
+ ```ts
86
+ if (import.meta.env.SSR) {
87
+ // your server code will be removed in the client build
88
+ }
89
+ else {
90
+ // your client code will be removed in the server build
91
+ }
92
+ ```
49
93
  ### Single Page SSG
50
94
 
51
95
  For SSG of an index page only (i.e. without `vue-router`); import `vite-ssg/single-page` instead, and only install `@unhead/vue` (`npm i -D vite-ssg @unhead/vue`).
@@ -74,7 +118,7 @@ The `ClientOnly` component is registered globally when the app is created.
74
118
 
75
119
  ## Document head
76
120
 
77
- We ship [`@unhead/vue`](https://unhead.harlanzw.com/integrations/vue/setup) to manage the document-head out of the box. You can use it directly in your pages/components.
121
+ We ship [`@unhead/vue v2`](https://unhead.unjs.io/docs/vue/head/guides/get-started/overview) to manage the document-head out of the box. You can use it directly in your pages/components.
78
122
  For example:
79
123
 
80
124
  ```html
@@ -99,7 +143,7 @@ useHead({
99
143
 
100
144
  That's all! No configuration is needed. Vite SSG will automatically handle the server-side rendering and merging.
101
145
 
102
- See [`@unhead/vue`'s docs](https://unhead.unjs.io/setup/vue/installation) for more usage information about `useHead`.
146
+ See [`@unhead/vue v2`'s docs](https://unhead.unjs.io/docs/vue/head/api/composables/use-head) for more usage information about `useHead`.
103
147
 
104
148
  ## Critical CSS
105
149
 
@@ -307,14 +351,14 @@ const { app, router, initialState, isClient, onSSRAppRendered } = ctx
307
351
  const pinia = createPinia()
308
352
  app.use(pinia)
309
353
 
310
- if (isClient) {
311
- pinia.state.value = (initialState.pinia) || {}
312
- }
313
- else {
354
+ if (import.meta.env.SSR) {
314
355
  onSSRAppRendered(() => {
315
356
  initialState.pinia = pinia.state.value
316
357
  })
317
358
  }
359
+ else {
360
+ pinia.state.value = (initialState.pinia) || {}
361
+ }
318
362
  ```
319
363
 
320
364
  ## Configuration
@@ -1,85 +1,30 @@
1
1
  import JSDOM from 'jsdom';
2
2
 
3
- /*
4
- MIT License
5
-
6
- Copyright for portions of global-jsdom are held by Rico Sta. Cruz, 2016 as part of
7
- jsdom-global. All other copyright for global-jsdom are held by jonathan schatz, 2017.
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- SOFTWARE.
26
- */
27
-
28
-
29
3
  const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>';
30
-
31
- // define this here so that we only ever dynamically populate KEYS once.
32
-
33
4
  const KEYS = [];
34
-
35
5
  function jsdomGlobal(html = defaultHtml, options = {}) {
36
- // Idempotency
37
- if (global.navigator
38
- && global.navigator.userAgent
39
- && global.navigator.userAgent.includes('Node.js')
40
- && global.document
41
- && typeof global.document.destroy === 'function') {
42
- return global.document.destroy
6
+ if (global.navigator && global.navigator.userAgent && global.navigator.userAgent.includes("Node.js") && global.document && typeof global.document.destroy === "function") {
7
+ return global.document.destroy;
43
8
  }
44
-
45
- // set a default url if we don't get one - otherwise things explode when we copy localstorage keys
46
- if (!('url' in options))
47
- Object.assign(options, { url: 'http://localhost:3000' });
48
-
49
- // enable pretendToBeVisual by default since react needs
50
- // window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
51
- if (!('pretendToBeVisual' in options))
9
+ if (!("url" in options))
10
+ Object.assign(options, { url: "http://localhost:3000" });
11
+ if (!("pretendToBeVisual" in options))
52
12
  Object.assign(options, { pretendToBeVisual: true });
53
-
54
13
  const jsdom = new JSDOM.JSDOM(html, options);
55
14
  const { window } = jsdom;
56
15
  const { document } = window;
57
-
58
- // generate our list of keys by enumerating document.window - this list may vary
59
- // based on the jsdom version. filter out internal methods as well as anything
60
- // that node already defines
61
-
62
16
  if (KEYS.length === 0) {
63
- KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
64
- // going to add our jsdom instance, see below
65
- KEYS.push('$jsdom');
17
+ KEYS.push(...Object.getOwnPropertyNames(window).filter((k) => !k.startsWith("_")).filter((k) => !(k in global)));
18
+ KEYS.push("$jsdom");
66
19
  }
67
-
68
- KEYS.forEach(key => global[key] = window[key]);
69
-
70
- // setup document / window / window.console
20
+ KEYS.forEach((key) => global[key] = window[key]);
71
21
  global.document = document;
72
22
  global.window = window;
73
23
  window.console = global.console;
74
-
75
- // add access to our jsdom instance
76
24
  global.$jsdom = jsdom;
77
-
78
- const cleanup = () => KEYS.forEach(key => delete global[key]);
79
-
25
+ const cleanup = () => KEYS.forEach((key) => delete global[key]);
80
26
  document.destroy = cleanup;
81
-
82
- return cleanup
27
+ return cleanup;
83
28
  }
84
29
 
85
30
  export { jsdomGlobal };
@@ -1,12 +1,11 @@
1
1
  import { Component } from 'vue';
2
- import { V as ViteSSGContext, a as ViteSSGClientOptions } from '../shared/vite-ssg-optimized.cf5cb4ee.mjs';
3
- export { R as RouterOptions, b as ViteSSGOptions } from '../shared/vite-ssg-optimized.cf5cb4ee.mjs';
2
+ import { V as ViteSSGContext, a as ViteSSGClientOptions } from '../shared/vite-ssg-optimized.C_FfKIMS.mjs';
3
+ export { R as RouterOptions, b as ViteSSGOptions } from '../shared/vite-ssg-optimized.C_FfKIMS.mjs';
4
4
  import '@unhead/vue';
5
5
  import 'beasties';
6
- import 'critters';
7
6
  import 'vue-router';
8
7
  import 'html-minifier-terser';
9
8
 
10
- declare function ViteSSG(App: Component, fn?: (context: ViteSSGContext<false>) => Promise<void> | void, options?: ViteSSGClientOptions): (client?: boolean) => Promise<ViteSSGContext<false>>;
9
+ declare function ViteSSG(App: Component, fn?: (context: ViteSSGContext<false>) => Promise<void> | void, options?: ViteSSGClientOptions): () => Promise<ViteSSGContext<false>>;
11
10
 
12
11
  export { ViteSSG, ViteSSGClientOptions, ViteSSGContext };
@@ -1,33 +1,44 @@
1
- import { createHead, createServerHead } from '@unhead/vue';
2
- import { createApp, createSSRApp } from 'vue';
3
- import { C as ClientOnly, d as documentReady } from '../shared/vite-ssg-optimized.5912142e.mjs';
4
- import { d as deserializeState } from '../shared/vite-ssg-optimized.579feabb.mjs';
1
+ import { createHead as createHead$1 } from '@unhead/vue/client';
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';
5
+ import { d as deserializeState } from '../shared/vite-ssg-optimized.C6pK7rvr.mjs';
5
6
 
6
- function ViteSSG(App, fn, options = {}) {
7
+ function ViteSSG(App, fn, options) {
7
8
  const {
8
9
  transformState,
9
10
  registerComponents = true,
10
11
  useHead = true,
11
12
  rootContainer = "#app"
12
- } = options;
13
- const isClient = typeof window !== "undefined";
14
- async function createApp$1(client = false) {
15
- const app = client ? createApp(App) : createSSRApp(App);
13
+ } = options ?? {};
14
+ async function createApp$1() {
15
+ const isClient = !import.meta.env.SSR;
16
+ const isHydrationMode = options?.hydration || isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
17
+ const app = import.meta.env.SSR || isHydrationMode ? createSSRApp(App) : createApp(App);
16
18
  let head;
17
19
  if (useHead) {
18
- head = client ? createHead() : createServerHead();
19
- app.use(head);
20
+ app.use(head = import.meta.env.SSR ? createHead() : createHead$1());
20
21
  }
21
22
  const appRenderCallbacks = [];
22
- const onSSRAppRendered = client ? () => {
23
- } : (cb) => appRenderCallbacks.push(cb);
23
+ const onSSRAppRendered = import.meta.env.SSR ? (cb) => appRenderCallbacks.push(cb) : () => {
24
+ };
24
25
  const triggerOnSSRAppRendered = () => {
25
26
  return Promise.all(appRenderCallbacks.map((cb) => cb()));
26
27
  };
27
- const context = { app, head, isClient, router: void 0, routes: void 0, initialState: {}, onSSRAppRendered, triggerOnSSRAppRendered, transformState };
28
+ const context = {
29
+ app,
30
+ head,
31
+ isClient: !import.meta.env.SSR,
32
+ router: void 0,
33
+ routes: void 0,
34
+ initialState: {},
35
+ onSSRAppRendered,
36
+ triggerOnSSRAppRendered,
37
+ transformState
38
+ };
28
39
  if (registerComponents)
29
40
  app.component("ClientOnly", ClientOnly);
30
- if (client) {
41
+ if (!import.meta.env.SSR) {
31
42
  await documentReady();
32
43
  context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || deserializeState(window.__INITIAL_STATE__);
33
44
  }
@@ -38,9 +49,9 @@ function ViteSSG(App, fn, options = {}) {
38
49
  initialState
39
50
  };
40
51
  }
41
- if (isClient) {
52
+ if (!import.meta.env.SSR) {
42
53
  (async () => {
43
- const { app } = await createApp$1(true);
54
+ const { app } = await createApp$1();
44
55
  app.mount(rootContainer, true);
45
56
  })();
46
57
  }
package/dist/index.d.mts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { Component } from 'vue';
2
- import { R as RouterOptions, V as ViteSSGContext, a as ViteSSGClientOptions } from './shared/vite-ssg-optimized.cf5cb4ee.mjs';
3
- export { b as ViteSSGOptions } from './shared/vite-ssg-optimized.cf5cb4ee.mjs';
2
+ import { R as RouterOptions, V as ViteSSGContext, a as ViteSSGClientOptions } from './shared/vite-ssg-optimized.C_FfKIMS.mjs';
3
+ export { b as ViteSSGOptions } from './shared/vite-ssg-optimized.C_FfKIMS.mjs';
4
4
  import '@unhead/vue';
5
5
  import 'beasties';
6
- import 'critters';
7
6
  import 'vue-router';
8
7
  import 'html-minifier-terser';
9
8
 
10
- declare function ViteSSG(App: Component, routerOptions: RouterOptions, fn?: (context: ViteSSGContext<true>) => Promise<void> | void, options?: ViteSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteSSGContext<true>>;
9
+ declare function ViteSSG(App: Component, routerOptions: RouterOptions, fn?: (context: ViteSSGContext<true>) => Promise<void> | void, options?: ViteSSGClientOptions): (routePath?: string) => Promise<ViteSSGContext<true>>;
11
10
 
12
11
  export { RouterOptions, ViteSSG, ViteSSGClientOptions, ViteSSGContext };
package/dist/index.mjs CHANGED
@@ -1,42 +1,42 @@
1
- import { createHead, createServerHead } from '@unhead/vue';
1
+ import { createHead as createHead$1 } from '@unhead/vue/client';
2
+ import { createHead } from '@unhead/vue/server';
2
3
  import { createApp, createSSRApp } from 'vue';
3
- import { createRouter, createWebHistory, createMemoryHistory } from 'vue-router';
4
- import { C as ClientOnly, d as documentReady } from './shared/vite-ssg-optimized.5912142e.mjs';
5
- import { d as deserializeState } from './shared/vite-ssg-optimized.579feabb.mjs';
4
+ import { createRouter, createMemoryHistory, createWebHistory } from 'vue-router';
5
+ import { C as ClientOnly, d as documentReady } from './shared/vite-ssg-optimized.ETIvV-80.mjs';
6
+ import { d as deserializeState } from './shared/vite-ssg-optimized.C6pK7rvr.mjs';
6
7
 
7
- function ViteSSG(App, routerOptions, fn, options = {}) {
8
+ function ViteSSG(App, routerOptions, fn, options) {
8
9
  const {
9
10
  transformState,
10
11
  registerComponents = true,
11
12
  useHead = true,
12
13
  rootContainer = "#app"
13
- } = options;
14
- const isClient = typeof window !== "undefined";
15
- async function createApp$1(client = false, routePath) {
16
- const isHydrationMode = isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
17
- const app = client && !isHydrationMode ? createApp(App) : createSSRApp(App);
14
+ } = options ?? {};
15
+ async function createApp$1(routePath) {
16
+ const isClient = !import.meta.env.SSR;
17
+ const isHydrationMode = options?.hydration || isClient && document.querySelectorAll("[data-server-rendered]").length > 0;
18
+ const app = import.meta.env.SSR || isHydrationMode ? createApp(App) : createSSRApp(App);
18
19
  let head;
19
20
  if (useHead) {
20
- head = client ? createHead() : createServerHead();
21
- app.use(head);
21
+ app.use(head = import.meta.env.SSR ? createHead() : createHead$1());
22
22
  }
23
23
  const router = createRouter({
24
- history: client ? createWebHistory(routerOptions.base) : createMemoryHistory(routerOptions.base),
24
+ history: import.meta.env.SSR ? createMemoryHistory(routerOptions.base) : createWebHistory(routerOptions.base),
25
25
  ...routerOptions
26
26
  });
27
27
  const { routes } = routerOptions;
28
28
  if (registerComponents)
29
29
  app.component("ClientOnly", ClientOnly);
30
30
  const appRenderCallbacks = [];
31
- const onSSRAppRendered = client ? () => {
32
- } : (cb) => appRenderCallbacks.push(cb);
31
+ const onSSRAppRendered = import.meta.env.SSR ? (cb) => appRenderCallbacks.push(cb) : () => {
32
+ };
33
33
  const triggerOnSSRAppRendered = () => {
34
34
  return Promise.all(appRenderCallbacks.map((cb) => cb()));
35
35
  };
36
36
  const context = {
37
37
  app,
38
38
  head,
39
- isClient,
39
+ isClient: !import.meta.env.SSR,
40
40
  router,
41
41
  routes,
42
42
  onSSRAppRendered,
@@ -45,7 +45,7 @@ function ViteSSG(App, routerOptions, fn, options = {}) {
45
45
  transformState,
46
46
  routePath
47
47
  };
48
- if (client) {
48
+ if (!import.meta.env.SSR) {
49
49
  await documentReady();
50
50
  context.initialState = transformState?.(window.__INITIAL_STATE__ || {}) || deserializeState(window.__INITIAL_STATE__);
51
51
  }
@@ -61,7 +61,7 @@ function ViteSSG(App, routerOptions, fn, options = {}) {
61
61
  }
62
62
  next();
63
63
  });
64
- if (!client) {
64
+ if (import.meta.env.SSR) {
65
65
  const route = context.routePath ?? "/";
66
66
  router.push(route);
67
67
  await router.isReady();
@@ -73,9 +73,9 @@ function ViteSSG(App, routerOptions, fn, options = {}) {
73
73
  initialState
74
74
  };
75
75
  }
76
- if (isClient) {
76
+ if (!import.meta.env.SSR) {
77
77
  (async () => {
78
- const { app, router } = await createApp$1(true);
78
+ const { app, router } = await createApp$1();
79
79
  await router.isReady();
80
80
  app.mount(rootContainer, true);
81
81
  })();
package/dist/node/cli.mjs CHANGED
@@ -1,45 +1,32 @@
1
1
  import process from 'node:process';
2
- import { gray, bold, red, reset, underline } from 'kolorist';
3
- import yargs from 'yargs';
4
- import { hideBin } from 'yargs/helpers';
5
- import { b as build } from '../shared/vite-ssg-optimized.15646db4.mjs';
6
- import 'node:module';
7
- import 'node:path';
2
+ import { gray, bold, red } from 'ansis';
3
+ import { cac } from 'cac';
4
+ import { b as build } from '../shared/vite-ssg-optimized.BfxECNw7.mjs';
8
5
  import '@unhead/ssr';
9
- import 'fs-extra';
10
- import 'vite';
11
- import '../shared/vite-ssg-optimized.579feabb.mjs';
12
6
  import 'html5parser';
13
7
  import 'node:worker_threads';
8
+ import 'node:fs';
9
+ import 'node:fs/promises';
10
+ import 'node:path';
11
+ import 'node:url';
12
+ import 'vite';
13
+ import '../shared/vite-ssg-optimized.C6pK7rvr.mjs';
14
14
 
15
- yargs(hideBin(process.argv)).scriptName("vite-ssg").usage("$0 [args]").command(
16
- "build",
17
- "Build SSG",
18
- (args) => args.option("script", {
19
- choices: ["sync", "async", "defer", "async defer"],
20
- describe: "Rewrites script loading timing"
21
- }).option("mock", {
22
- type: "boolean",
23
- describe: "Mock browser globals (window, document, etc.) for SSG"
24
- }).option("config", {
25
- alias: "c",
26
- type: "string",
27
- describe: "The vite config file to use"
28
- }).option("base", {
29
- alias: "b",
30
- type: "string",
31
- describe: "The base path to render"
32
- }).option("skip-build", {
33
- type: "boolean",
34
- describe: "Skip build if already have build in ssg-out dir"
35
- }),
36
- async (args) => {
37
- const { config: configFile = void 0, ...ssgOptions } = args;
38
- await build(ssgOptions, { configFile });
15
+ const cli = cac("vite-ssg");
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
+ const { config: configFile = void 0, ...ssgOptions } = args;
18
+ if (args.script && !["sync", "async", "defer", "async defer"].includes(args.script)) {
19
+ console.error(`
20
+ ${gray("[vite-ssg]")} ${bold(red("Invalid script option."))}`);
21
+ process.exit(1);
39
22
  }
40
- ).fail((msg, err, yargs2) => {
23
+ await build(ssgOptions, { configFile });
24
+ });
25
+ cli.on("command:*", () => {
41
26
  console.error(`
42
- ${gray("[vite-ssg]")} ${bold(red("An internal error occurred."))}`);
43
- console.error(`${gray("[vite-ssg]")} ${reset(`Please report an issue, if none already exists: ${underline("https://github.com/antfu/vite-ssg/issues")}`)}`);
44
- yargs2.exit(1, err);
45
- }).showHelpOnFail(false).help().argv;
27
+ ${gray("[vite-ssg]")} ${bold(red("Invalid command."))}`);
28
+ cli.outputHelp();
29
+ process.exit(1);
30
+ });
31
+ cli.help();
32
+ cli.parse(process.argv);
package/dist/node.d.mts CHANGED
@@ -1,9 +1,13 @@
1
- export { b as build } from './shared/vite-ssg-optimized.892682c8.mjs';
2
- import 'vite';
3
- import './shared/vite-ssg-optimized.cf5cb4ee.mjs';
1
+ import { InlineConfig } from 'vite';
2
+ import { b as ViteSSGOptions } from './shared/vite-ssg-optimized.C_FfKIMS.mjs';
4
3
  import '@unhead/vue';
5
4
  import 'beasties';
6
- import 'critters';
7
5
  import 'vue';
8
6
  import 'vue-router';
9
7
  import 'html-minifier-terser';
8
+
9
+ declare function build(ssgOptions?: Partial<ViteSSGOptions & {
10
+ 'skip-build'?: boolean;
11
+ }>, viteConfig?: InlineConfig): Promise<void>;
12
+
13
+ export { build };
package/dist/node.mjs CHANGED
@@ -1,11 +1,12 @@
1
- export { b as build } from './shared/vite-ssg-optimized.15646db4.mjs';
2
- import 'node:module';
3
- import 'node:path';
4
- import 'node:process';
1
+ export { b as build } from './shared/vite-ssg-optimized.BfxECNw7.mjs';
5
2
  import '@unhead/ssr';
6
- import 'fs-extra';
7
- import 'kolorist';
8
- import 'vite';
9
- import './shared/vite-ssg-optimized.579feabb.mjs';
10
3
  import 'html5parser';
11
4
  import 'node:worker_threads';
5
+ import 'ansis';
6
+ import 'node:fs';
7
+ import 'node:fs/promises';
8
+ import 'node:path';
9
+ import 'node:process';
10
+ import 'node:url';
11
+ import 'vite';
12
+ import './shared/vite-ssg-optimized.C6pK7rvr.mjs';
@@ -1,27 +1,15 @@
1
- import { M as Manifest } from './vite-ssg-optimized.892682c8.mjs';
2
- import { ViteSSGOptions } from 'vite-ssg';
3
- import { Options } from 'beasties';
4
- import { Options as Options$1 } from 'html-minifier-terser';
5
- import 'vite';
6
- import './vite-ssg-optimized.cf5cb4ee.mjs';
1
+ import { b as ViteSSGOptions } from './vite-ssg-optimized.C_FfKIMS.mjs';
7
2
  import '@unhead/vue';
8
- import 'critters';
3
+ import 'beasties';
9
4
  import 'vue';
10
5
  import 'vue-router';
6
+ import 'html-minifier-terser';
11
7
 
12
8
  interface WorkerDataEntry {
13
- serverEntry: string;
14
9
  workerId: number | string;
15
- format: 'esm' | 'cjs';
16
10
  out: string;
17
11
  dirStyle: ViteSSGOptions['dirStyle'];
18
- beastiesOptions: Options | false;
19
12
  mode?: string;
20
- ssrManifest: Manifest;
21
- indexHTML: string;
22
- rootContainerId: string;
23
- formatting: ViteSSGOptions['formatting'];
24
- minifyOptions: Options$1;
25
13
  viteConfig: {
26
14
  configFile?: string;
27
15
  };