vite-ssg-optimized 0.24.2-optimized.22 → 0.24.2-optimized.23

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.
package/dist/node/cli.cjs CHANGED
@@ -4,7 +4,7 @@ const process = require('node:process');
4
4
  const kolorist = require('kolorist');
5
5
  const yargs = require('yargs');
6
6
  const helpers = require('yargs/helpers');
7
- const node = require('../shared/vite-ssg-optimized.3da368f4.cjs');
7
+ const node = require('../shared/vite-ssg-optimized.524d8794.cjs');
8
8
  require('node:module');
9
9
  require('node:path');
10
10
  require('@unhead/ssr');
package/dist/node/cli.mjs CHANGED
@@ -2,7 +2,7 @@ import process from 'node:process';
2
2
  import { gray, bold, red, reset, underline } from 'kolorist';
3
3
  import yargs from 'yargs';
4
4
  import { hideBin } from 'yargs/helpers';
5
- import { b as build } from '../shared/vite-ssg-optimized.5a003b5d.mjs';
5
+ import { b as build } from '../shared/vite-ssg-optimized.2fd44d5b.mjs';
6
6
  import 'node:module';
7
7
  import 'node:path';
8
8
  import '@unhead/ssr';
package/dist/node.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const node = require('./shared/vite-ssg-optimized.3da368f4.cjs');
3
+ const node = require('./shared/vite-ssg-optimized.524d8794.cjs');
4
4
  require('node:module');
5
5
  require('node:path');
6
6
  require('node:process');
package/dist/node.d.cts CHANGED
@@ -1,9 +1,14 @@
1
- export { b as build } from './shared/vite-ssg-optimized.27bed688.cjs';
2
- import 'vite';
3
- import './shared/vite-ssg-optimized.341e382e.cjs';
1
+ import { InlineConfig } from 'vite';
2
+ import { b as ViteSSGOptions } from './shared/vite-ssg-optimized.341e382e.cjs';
4
3
  import '@unhead/vue';
5
4
  import 'beasties';
6
5
  import 'critters';
7
6
  import 'vue';
8
7
  import 'vue-router';
9
8
  import 'html-minifier-terser';
9
+
10
+ declare function build(ssgOptions?: Partial<ViteSSGOptions & {
11
+ 'skip-build'?: boolean;
12
+ }>, viteConfig?: InlineConfig): Promise<void>;
13
+
14
+ export { build };
package/dist/node.d.mts CHANGED
@@ -1,9 +1,14 @@
1
- export { b as build } from './shared/vite-ssg-optimized.f03a17e6.mjs';
2
- import 'vite';
3
- import './shared/vite-ssg-optimized.341e382e.mjs';
1
+ import { InlineConfig } from 'vite';
2
+ import { b as ViteSSGOptions } from './shared/vite-ssg-optimized.341e382e.mjs';
4
3
  import '@unhead/vue';
5
4
  import 'beasties';
6
5
  import 'critters';
7
6
  import 'vue';
8
7
  import 'vue-router';
9
8
  import 'html-minifier-terser';
9
+
10
+ declare function build(ssgOptions?: Partial<ViteSSGOptions & {
11
+ 'skip-build'?: boolean;
12
+ }>, viteConfig?: InlineConfig): Promise<void>;
13
+
14
+ export { build };
package/dist/node.d.ts CHANGED
@@ -1,9 +1,14 @@
1
- export { b as build } from './shared/vite-ssg-optimized.f1a9229c.js';
2
- import 'vite';
3
- import './shared/vite-ssg-optimized.341e382e.js';
1
+ import { InlineConfig } from 'vite';
2
+ import { b as ViteSSGOptions } from './shared/vite-ssg-optimized.341e382e.js';
4
3
  import '@unhead/vue';
5
4
  import 'beasties';
6
5
  import 'critters';
7
6
  import 'vue';
8
7
  import 'vue-router';
9
8
  import 'html-minifier-terser';
9
+
10
+ declare function build(ssgOptions?: Partial<ViteSSGOptions & {
11
+ 'skip-build'?: boolean;
12
+ }>, viteConfig?: InlineConfig): Promise<void>;
13
+
14
+ export { build };
package/dist/node.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { b as build } from './shared/vite-ssg-optimized.5a003b5d.mjs';
1
+ export { b as build } from './shared/vite-ssg-optimized.2fd44d5b.mjs';
2
2
  import 'node:module';
3
3
  import 'node:path';
4
4
  import 'node:process';
@@ -2,7 +2,7 @@
2
2
 
3
3
  const node_module = require('node:module');
4
4
  const node_worker_threads = require('node:worker_threads');
5
- const node = require('./vite-ssg-optimized.3da368f4.cjs');
5
+ const node = require('./vite-ssg-optimized.524d8794.cjs');
6
6
  const kolorist = require('kolorist');
7
7
  const vite = require('vite');
8
8
  require('node:path');
@@ -13,30 +13,38 @@ require('./vite-ssg-optimized.bee8a5a9.cjs');
13
13
  require('html5parser');
14
14
 
15
15
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
16
+ async function getBeastiesOrCritters(outDir, options = {}) {
17
+ try {
18
+ const BeastiesClass = (await import('beasties')).default;
19
+ return new BeastiesClass({
20
+ path: outDir,
21
+ logLevel: "warn",
22
+ external: true,
23
+ inlineFonts: true,
24
+ preloadFonts: true,
25
+ ...options
26
+ });
27
+ } catch {
28
+ }
29
+ try {
30
+ const CrittersClass = (await import('critters')).default;
31
+ console.warn("`critters` is deprecated. Please use `beasties` instead.");
32
+ return new CrittersClass({
33
+ path: outDir,
34
+ logLevel: "warn",
35
+ external: true,
36
+ inlineFonts: true,
37
+ preloadFonts: true,
38
+ ...options
39
+ });
40
+ } catch {
41
+ return void 0;
42
+ }
43
+ }
44
+
16
45
  (async () => {
17
- const plainnify = (m) => {
18
- if (m instanceof Function) {
19
- return void 0;
20
- }
21
- if (Array.isArray(m)) {
22
- return m.map(plainnify);
23
- }
24
- if (typeof m === "object" && m !== null) {
25
- if (m instanceof Error || "stack" in m) {
26
- return {
27
- message: m.message,
28
- stack: m.stack
29
- };
30
- }
31
- return Object.entries(m).reduce((acc, [key, value]) => {
32
- acc[key] = plainnify(value);
33
- return acc;
34
- }, {});
35
- }
36
- return m?.toString();
37
- };
38
46
  const fnLog = (level = "info", ...msg) => {
39
- const newMsg = msg.map(plainnify);
47
+ const newMsg = msg.map(node.plainify);
40
48
  node_worker_threads.parentPort.postMessage({ type: "log", args: newMsg, level });
41
49
  };
42
50
  globalThis.console = Object.assign(globalThis.console, {
@@ -47,7 +55,7 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
47
55
  trace: fnLog.bind(globalThis.console, "trace"),
48
56
  debug: fnLog.bind(globalThis.console, "debug")
49
57
  });
50
- const { serverEntry, out, beastiesOptions, viteConfig, mode, format, dirStyle, ...extraOpts } = node_worker_threads.workerData;
58
+ const { format, out, dirStyle, viteConfig, mode, ...extraOpts } = node_worker_threads.workerData;
51
59
  const nodeEnv = process.env.NODE_ENV || "production";
52
60
  const config = await vite.resolveConfig(viteConfig, "build", mode, nodeEnv);
53
61
  const {
@@ -55,15 +63,18 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
55
63
  onBeforePageRender
56
64
  // onDonePageRender,
57
65
  } = config.ssgOptions || {};
66
+ let beasties = void 0;
58
67
  const { renderToString } = await import('vue/server-renderer');
59
68
  const outDir = out.replace(process.cwd(), "").replace(/^\//g, "");
60
69
  const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/build.worker.cjs', document.baseURI).href)));
61
- const beasties = beastiesOptions !== false ? await node.getBeastiesOrCritters(outDir, beastiesOptions) : void 0;
62
- if (beasties)
63
- console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.blue("Critical CSS generation enabled via `beasties`")}`);
64
- const { createApp } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
65
70
  const execMap = {
66
71
  executeTaskFn: async (opts) => {
72
+ const { serverEntry } = opts;
73
+ const { createApp } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
74
+ const beastiesOptions = opts.beastiesOptions;
75
+ beasties ?? (beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, beastiesOptions) : void 0);
76
+ if (beasties)
77
+ console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.blue("Critical CSS generation enabled via `beasties`")}`);
67
78
  const newOpts = {
68
79
  ...extraOpts,
69
80
  out,
@@ -80,6 +91,18 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
80
91
  ...opts
81
92
  };
82
93
  return node.executeTaskFn(newOpts);
94
+ },
95
+ buildClient: async (...args) => {
96
+ let [_config, _viteConfig] = args;
97
+ _config = Object.assign({}, config, _config);
98
+ _viteConfig = Object.assign({}, viteConfig, _viteConfig);
99
+ return await node.buildClient(_config, _viteConfig);
100
+ },
101
+ buildServer: async (...args) => {
102
+ let [_config, _viteConfig, _opts] = args;
103
+ _config = Object.assign({}, config, _config);
104
+ _viteConfig = Object.assign({}, viteConfig, _viteConfig);
105
+ return await node.buildServer(_config, _viteConfig, _opts);
83
106
  }
84
107
  };
85
108
  node_worker_threads.parentPort?.on("message", async (message) => {
@@ -87,12 +110,8 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
87
110
  if (type in execMap) {
88
111
  node_worker_threads.parentPort.postMessage(`running ${type}`);
89
112
  try {
90
- const result = await execMap[type](...args ?? []);
91
- if (result.appCtx) {
92
- Object.assign(result, {
93
- appCtx: result.appCtx.router.push(result.route)
94
- });
95
- }
113
+ let result = await execMap[type](...args ?? []);
114
+ result = node.plainify(result);
96
115
  node_worker_threads.parentPort.postMessage({ type: "result", id, result });
97
116
  } catch (e) {
98
117
  const message2 = e.message || e.toString();
@@ -1,27 +1,17 @@
1
- import { M as Manifest } from './vite-ssg-optimized.27bed688.cjs';
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.341e382e.cjs';
1
+ import { b as ViteSSGOptions } from './vite-ssg-optimized.341e382e.cjs';
7
2
  import '@unhead/vue';
3
+ import 'beasties';
8
4
  import 'critters';
9
5
  import 'vue';
10
6
  import 'vue-router';
7
+ import 'html-minifier-terser';
11
8
 
12
9
  interface WorkerDataEntry {
13
- serverEntry: string;
14
10
  workerId: number | string;
15
11
  format: 'esm' | 'cjs';
16
12
  out: string;
17
13
  dirStyle: ViteSSGOptions['dirStyle'];
18
- beastiesOptions: Options | false;
19
14
  mode?: string;
20
- ssrManifest: Manifest;
21
- indexHTML: string;
22
- rootContainerId: string;
23
- formatting: ViteSSGOptions['formatting'];
24
- minifyOptions: Options$1;
25
15
  viteConfig: {
26
16
  configFile?: string;
27
17
  };
@@ -1,27 +1,17 @@
1
- import { M as Manifest } from './vite-ssg-optimized.f03a17e6.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.341e382e.mjs';
1
+ import { b as ViteSSGOptions } from './vite-ssg-optimized.341e382e.mjs';
7
2
  import '@unhead/vue';
3
+ import 'beasties';
8
4
  import 'critters';
9
5
  import 'vue';
10
6
  import 'vue-router';
7
+ import 'html-minifier-terser';
11
8
 
12
9
  interface WorkerDataEntry {
13
- serverEntry: string;
14
10
  workerId: number | string;
15
11
  format: 'esm' | 'cjs';
16
12
  out: string;
17
13
  dirStyle: ViteSSGOptions['dirStyle'];
18
- beastiesOptions: Options | false;
19
14
  mode?: string;
20
- ssrManifest: Manifest;
21
- indexHTML: string;
22
- rootContainerId: string;
23
- formatting: ViteSSGOptions['formatting'];
24
- minifyOptions: Options$1;
25
15
  viteConfig: {
26
16
  configFile?: string;
27
17
  };
@@ -1,27 +1,17 @@
1
- import { M as Manifest } from './vite-ssg-optimized.f1a9229c.js';
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.341e382e.js';
1
+ import { b as ViteSSGOptions } from './vite-ssg-optimized.341e382e.js';
7
2
  import '@unhead/vue';
3
+ import 'beasties';
8
4
  import 'critters';
9
5
  import 'vue';
10
6
  import 'vue-router';
7
+ import 'html-minifier-terser';
11
8
 
12
9
  interface WorkerDataEntry {
13
- serverEntry: string;
14
10
  workerId: number | string;
15
11
  format: 'esm' | 'cjs';
16
12
  out: string;
17
13
  dirStyle: ViteSSGOptions['dirStyle'];
18
- beastiesOptions: Options | false;
19
14
  mode?: string;
20
- ssrManifest: Manifest;
21
- indexHTML: string;
22
- rootContainerId: string;
23
- formatting: ViteSSGOptions['formatting'];
24
- minifyOptions: Options$1;
25
15
  viteConfig: {
26
16
  configFile?: string;
27
17
  };
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { parentPort, workerData } from 'node:worker_threads';
3
- import { g as getBeastiesOrCritters, e as executeTaskFn } from './vite-ssg-optimized.5a003b5d.mjs';
4
- import { gray, blue, red } from 'kolorist';
3
+ import { p as plainify, e as executeTaskFn, a as buildClient, c as buildServer } from './vite-ssg-optimized.2fd44d5b.mjs';
4
+ import { red, gray, blue } from 'kolorist';
5
5
  import { resolveConfig } from 'vite';
6
6
  import 'node:path';
7
7
  import 'node:process';
@@ -10,30 +10,38 @@ import 'fs-extra';
10
10
  import './vite-ssg-optimized.579feabb.mjs';
11
11
  import 'html5parser';
12
12
 
13
+ async function getBeastiesOrCritters(outDir, options = {}) {
14
+ try {
15
+ const BeastiesClass = (await import('beasties')).default;
16
+ return new BeastiesClass({
17
+ path: outDir,
18
+ logLevel: "warn",
19
+ external: true,
20
+ inlineFonts: true,
21
+ preloadFonts: true,
22
+ ...options
23
+ });
24
+ } catch {
25
+ }
26
+ try {
27
+ const CrittersClass = (await import('critters')).default;
28
+ console.warn("`critters` is deprecated. Please use `beasties` instead.");
29
+ return new CrittersClass({
30
+ path: outDir,
31
+ logLevel: "warn",
32
+ external: true,
33
+ inlineFonts: true,
34
+ preloadFonts: true,
35
+ ...options
36
+ });
37
+ } catch {
38
+ return void 0;
39
+ }
40
+ }
41
+
13
42
  (async () => {
14
- const plainnify = (m) => {
15
- if (m instanceof Function) {
16
- return void 0;
17
- }
18
- if (Array.isArray(m)) {
19
- return m.map(plainnify);
20
- }
21
- if (typeof m === "object" && m !== null) {
22
- if (m instanceof Error || "stack" in m) {
23
- return {
24
- message: m.message,
25
- stack: m.stack
26
- };
27
- }
28
- return Object.entries(m).reduce((acc, [key, value]) => {
29
- acc[key] = plainnify(value);
30
- return acc;
31
- }, {});
32
- }
33
- return m?.toString();
34
- };
35
43
  const fnLog = (level = "info", ...msg) => {
36
- const newMsg = msg.map(plainnify);
44
+ const newMsg = msg.map(plainify);
37
45
  parentPort.postMessage({ type: "log", args: newMsg, level });
38
46
  };
39
47
  globalThis.console = Object.assign(globalThis.console, {
@@ -44,7 +52,7 @@ import 'html5parser';
44
52
  trace: fnLog.bind(globalThis.console, "trace"),
45
53
  debug: fnLog.bind(globalThis.console, "debug")
46
54
  });
47
- const { serverEntry, out, beastiesOptions, viteConfig, mode, format, dirStyle, ...extraOpts } = workerData;
55
+ const { format, out, dirStyle, viteConfig, mode, ...extraOpts } = workerData;
48
56
  const nodeEnv = process.env.NODE_ENV || "production";
49
57
  const config = await resolveConfig(viteConfig, "build", mode, nodeEnv);
50
58
  const {
@@ -52,15 +60,18 @@ import 'html5parser';
52
60
  onBeforePageRender
53
61
  // onDonePageRender,
54
62
  } = config.ssgOptions || {};
63
+ let beasties = void 0;
55
64
  const { renderToString } = await import('vue/server-renderer');
56
65
  const outDir = out.replace(process.cwd(), "").replace(/^\//g, "");
57
66
  const _require = createRequire(import.meta.url);
58
- const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, beastiesOptions) : void 0;
59
- if (beasties)
60
- console.log(`${gray("[vite-ssg]")} ${blue("Critical CSS generation enabled via `beasties`")}`);
61
- const { createApp } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
62
67
  const execMap = {
63
68
  executeTaskFn: async (opts) => {
69
+ const { serverEntry } = opts;
70
+ const { createApp } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
71
+ const beastiesOptions = opts.beastiesOptions;
72
+ beasties ?? (beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, beastiesOptions) : void 0);
73
+ if (beasties)
74
+ console.log(`${gray("[vite-ssg]")} ${blue("Critical CSS generation enabled via `beasties`")}`);
64
75
  const newOpts = {
65
76
  ...extraOpts,
66
77
  out,
@@ -77,6 +88,18 @@ import 'html5parser';
77
88
  ...opts
78
89
  };
79
90
  return executeTaskFn(newOpts);
91
+ },
92
+ buildClient: async (...args) => {
93
+ let [_config, _viteConfig] = args;
94
+ _config = Object.assign({}, config, _config);
95
+ _viteConfig = Object.assign({}, viteConfig, _viteConfig);
96
+ return await buildClient(_config, _viteConfig);
97
+ },
98
+ buildServer: async (...args) => {
99
+ let [_config, _viteConfig, _opts] = args;
100
+ _config = Object.assign({}, config, _config);
101
+ _viteConfig = Object.assign({}, viteConfig, _viteConfig);
102
+ return await buildServer(_config, _viteConfig, _opts);
80
103
  }
81
104
  };
82
105
  parentPort?.on("message", async (message) => {
@@ -84,12 +107,8 @@ import 'html5parser';
84
107
  if (type in execMap) {
85
108
  parentPort.postMessage(`running ${type}`);
86
109
  try {
87
- const result = await execMap[type](...args ?? []);
88
- if (result.appCtx) {
89
- Object.assign(result, {
90
- appCtx: result.appCtx.router.push(result.route)
91
- });
92
- }
110
+ let result = await execMap[type](...args ?? []);
111
+ result = plainify(result);
93
112
  parentPort.postMessage({ type: "result", id, result });
94
113
  } catch (e) {
95
114
  const message2 = e.message || e.toString();
@@ -830,35 +830,6 @@ class PQueue extends EventEmitter {
830
830
  }
831
831
  }
832
832
 
833
- async function getBeastiesOrCritters(outDir, options = {}) {
834
- try {
835
- const BeastiesClass = (await import('beasties')).default;
836
- return new BeastiesClass({
837
- path: outDir,
838
- logLevel: "warn",
839
- external: true,
840
- inlineFonts: true,
841
- preloadFonts: true,
842
- ...options
843
- });
844
- } catch {
845
- }
846
- try {
847
- const CrittersClass = (await import('critters')).default;
848
- console.warn("`critters` is deprecated. Please use `beasties` instead.");
849
- return new CrittersClass({
850
- path: outDir,
851
- logLevel: "warn",
852
- external: true,
853
- inlineFonts: true,
854
- preloadFonts: true,
855
- ...options
856
- });
857
- } catch {
858
- return void 0;
859
- }
860
- }
861
-
862
833
  function isMatchOption(node, opts) {
863
834
  if (opts.match.tag && !(node.name === opts.match.tag)) {
864
835
  return false;
@@ -1112,10 +1083,14 @@ async function buildClient(config, viteConfig) {
1112
1083
  mode: config.mode
1113
1084
  }));
1114
1085
  }
1115
- async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format }) {
1086
+ async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format, mock }) {
1116
1087
  buildLog("Build for server...");
1117
1088
  process$1.env.VITE_SSG = "true";
1118
1089
  const { base } = config;
1090
+ if (mock) {
1091
+ const { jsdomGlobal } = await import('../chunks/jsdomGlobal.mjs');
1092
+ jsdomGlobal();
1093
+ }
1119
1094
  await build$1(mergeConfig(viteConfig, {
1120
1095
  base,
1121
1096
  build: {
@@ -1136,6 +1111,19 @@ async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format }) {
1136
1111
  mode: config.mode
1137
1112
  }));
1138
1113
  }
1114
+ function createProxy(options) {
1115
+ const workerExt = options.format === "esm" ? ".mjs" : ".cjs";
1116
+ const workerProxy = new BuildWorkerProxy(new URL(`./build.worker${workerExt}`, import.meta.url), {
1117
+ env: process$1.env,
1118
+ workerData: options
1119
+ });
1120
+ process$1.on("SIGINT", workerProxy.terminate.bind(workerProxy));
1121
+ process$1.on("SIGTERM", workerProxy.terminate.bind(workerProxy));
1122
+ process$1.on("SIGBREAK", workerProxy.terminate.bind(workerProxy));
1123
+ process$1.on("beforeExit", workerProxy.terminate.bind(workerProxy));
1124
+ process$1.on("exit", workerProxy.terminate.bind(workerProxy));
1125
+ return workerProxy;
1126
+ }
1139
1127
  async function build(ssgOptions = {}, viteConfig = {}) {
1140
1128
  const nodeEnv = process$1.env.NODE_ENV || "production";
1141
1129
  const mode = process$1.env.MODE || ssgOptions.mode || nodeEnv;
@@ -1165,6 +1153,42 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1165
1153
  rootContainerId = "app"
1166
1154
  } = Object.assign({}, config.ssgOptions || {}, ssgOptions);
1167
1155
  const ssgOut = isAbsolute(_ssgOutDir) ? _ssgOutDir : join(root, _ssgOutDir);
1156
+ const numberOfWorkers = Math.max(1, _numberOfWorkers);
1157
+ console.log(`${gray("[vite-ssg]")} ${blue(`Using ${numberOfWorkers} workers`)}`);
1158
+ const workers = Array.from({ length: numberOfWorkers }, (_, index) => createProxy({
1159
+ format,
1160
+ out,
1161
+ dirStyle,
1162
+ workerId: index,
1163
+ viteConfig: {
1164
+ configFile: config.configFile
1165
+ }
1166
+ }));
1167
+ const terminateWorkers = () => {
1168
+ workers.splice(0, workers.length).forEach((worker) => worker.terminate());
1169
+ };
1170
+ let workerIndex = 0;
1171
+ const maxTasksPerWorker = Math.ceil(concurrency / numberOfWorkers);
1172
+ const workersInUse = /* @__PURE__ */ new Map();
1173
+ const workerTasksRunning = (w) => workersInUse.get(w)?.length || 0;
1174
+ const selectIdleWorker = () => workers.filter((w) => workerTasksRunning(w) < maxTasksPerWorker).sort((a, b) => workerTasksRunning(a) - workerTasksRunning(b))[0];
1175
+ const selectWorker = async (workerIndex2) => {
1176
+ const index = workerIndex2 ?? Math.round(Math.random() * numberOfWorkers);
1177
+ const maybeWorker = workers[index % numberOfWorkers];
1178
+ const worker = maybeWorker && workerTasksRunning(maybeWorker) < maxTasksPerWorker ? maybeWorker : selectIdleWorker();
1179
+ if (!worker) {
1180
+ await Promise.race(Array.from(workersInUse.values()).flat());
1181
+ return selectWorker(workerIndex2);
1182
+ }
1183
+ const workerPromises = workersInUse.get(worker) || [];
1184
+ const delayPromise = new Promise((resolve) => setImmediate(resolve));
1185
+ workersInUse.set(worker, [...workerPromises, delayPromise]);
1186
+ delayPromise.finally(() => {
1187
+ workerPromises.splice(workerPromises.indexOf(delayPromise), 1);
1188
+ workersInUse.set(worker, workerPromises);
1189
+ });
1190
+ return worker;
1191
+ };
1168
1192
  let willRunBuild = true;
1169
1193
  if (fs.existsSync(ssgOut)) {
1170
1194
  willRunBuild = !ssgOptions["skip-build"];
@@ -1172,15 +1196,15 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1172
1196
  await fs.remove(ssgOut);
1173
1197
  }
1174
1198
  }
1175
- if (willRunBuild)
1176
- await buildClient(config, viteConfig);
1177
- if (mock) {
1178
- const { jsdomGlobal } = await import('../chunks/jsdomGlobal.mjs');
1179
- jsdomGlobal();
1199
+ if (willRunBuild) {
1200
+ const clientWorker = await selectWorker(0);
1201
+ await execInWorker(clientWorker, buildClient, config, viteConfig);
1180
1202
  }
1181
1203
  const ssrEntry = await resolveAlias(config, entry);
1182
- if (willRunBuild)
1183
- await buildServer(config, viteConfig, { ssrEntry, ssgOut, format });
1204
+ if (willRunBuild) {
1205
+ const serverWorker = await selectWorker(1);
1206
+ await execInWorker(serverWorker, buildServer, config, viteConfig, { ssrEntry, ssgOut, format, mock });
1207
+ }
1184
1208
  const prefix = format === "esm" && process$1.platform === "win32" ? "file://" : "";
1185
1209
  const ext = format === "esm" ? ".mjs" : ".cjs";
1186
1210
  const serverEntry = prefix + join(ssgOut, parse(ssrEntry).name + ext).replace(/\\/g, "/");
@@ -1191,9 +1215,6 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1191
1215
  let routesPaths = includeAllRoutes ? routesToPaths(routes) : await includedRoutes(routesToPaths(routes), routes || []);
1192
1216
  routesPaths = Array.from(new Set(routesPaths));
1193
1217
  buildLog("Rendering Pages...", routesPaths.length);
1194
- const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, beastiesOptions) : void 0;
1195
- if (beasties)
1196
- console.log(`${gray("[vite-ssg]")} ${blue("Critical CSS generation enabled via `beasties`")}`);
1197
1218
  const {
1198
1219
  path: _ssrManifestPath,
1199
1220
  content: ssrManifestRaw
@@ -1209,76 +1230,28 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1209
1230
  const IS_PROD = nodeEnv === "production";
1210
1231
  indexHTML = await formatHtml(indexHTML, IS_PROD ? "minify" : formatting, minifyOptions);
1211
1232
  const queue = new PQueue({ concurrency });
1212
- const workerExt = format === "esm" ? ".mjs" : ".cjs";
1213
- const createProxy = (index) => {
1214
- const workerProxy = new BuildWorkerProxy(new URL(`./build.worker${workerExt}`, import.meta.url), {
1215
- env: process$1.env,
1216
- workerData: {
1217
- workerId: index,
1218
- serverEntry,
1219
- ssrManifest,
1220
- format,
1221
- out,
1222
- beastiesOptions,
1223
- dirStyle,
1224
- indexHTML,
1225
- rootContainerId,
1226
- formatting,
1227
- minifyOptions,
1228
- viteConfig: {
1229
- configFile: config.configFile
1230
- }
1231
- }
1232
- });
1233
- return workerProxy;
1234
- };
1235
- const numberOfWorkers = Math.max(1, _numberOfWorkers);
1236
- console.log(`${gray("[vite-ssg]")} ${blue(`Using ${numberOfWorkers} workers`)}`);
1237
- const workers = Array.from({ length: numberOfWorkers }, (_, index) => createProxy(index));
1238
- const terminateWorkers = () => {
1239
- workers.splice(0, workers.length).forEach((worker) => worker.terminate());
1240
- };
1241
- process$1.on("SIGINT", terminateWorkers);
1242
- process$1.on("SIGTERM", terminateWorkers);
1243
- process$1.on("SIGBREAK", terminateWorkers);
1244
- process$1.on("beforeExit", terminateWorkers);
1245
- process$1.on("exit", terminateWorkers);
1246
- let workerIndex = 0;
1247
- const maxTasksPerWorker = Math.ceil(concurrency / numberOfWorkers);
1248
- const workersInUse = /* @__PURE__ */ new Map();
1249
- const workerTasksRunning = (w) => workersInUse.get(w)?.length || 0;
1250
- const selectIdleWorker = () => workers.filter((w) => workerTasksRunning(w) < maxTasksPerWorker).sort((a, b) => workerTasksRunning(a) - workerTasksRunning(b))[0];
1251
- const selectWorker = async (workerIndex2) => {
1252
- const index = workerIndex2 ?? Math.round(Math.random() * numberOfWorkers);
1253
- const maybeWorker = workers[index % numberOfWorkers];
1254
- const worker = maybeWorker && workerTasksRunning(maybeWorker) < maxTasksPerWorker ? maybeWorker : selectIdleWorker();
1255
- if (!worker) {
1256
- await Promise.race(Array.from(workersInUse.values()).flat());
1257
- return selectWorker(workerIndex2);
1258
- }
1259
- const workerPromises = workersInUse.get(worker) || [];
1260
- const delayPromise = new Promise((resolve) => setImmediate(resolve));
1261
- workersInUse.set(worker, [...workerPromises, delayPromise]);
1262
- delayPromise.finally(() => {
1263
- workerPromises.splice(workerPromises.indexOf(delayPromise), 1);
1264
- workersInUse.set(worker, workerPromises);
1265
- });
1266
- return worker;
1267
- };
1268
1233
  for (const route of routesPaths) {
1269
1234
  await queue.onSizeLessThan(concurrency);
1270
1235
  queue.add(async () => {
1271
1236
  const workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
1272
1237
  let retryCount = 0;
1273
1238
  const maxRetries = 3;
1274
- const taskPromise = executeTaskInWorker(workerProxy, {
1275
- route
1276
- }).catch((e) => {
1239
+ const execOpts = {
1240
+ route,
1241
+ ssrManifest,
1242
+ indexHTML,
1243
+ rootContainerId,
1244
+ formatting,
1245
+ minifyOptions,
1246
+ // out,
1247
+ // dirStyle,
1248
+ beastiesOptions,
1249
+ serverEntry
1250
+ };
1251
+ const taskPromise = executeTaskInWorker(workerProxy, execOpts).catch((e) => {
1277
1252
  if (retryCount++ < maxRetries) {
1278
1253
  console.log(`${gray("[vite-ssg]")} ${yellow(`Retrying ${retryCount} of ${maxRetries} for route: ${cyan(route)}`)}`);
1279
- return executeTaskInWorker(workerProxy, {
1280
- route
1281
- });
1254
+ return executeTaskInWorker(workerProxy, execOpts);
1282
1255
  }
1283
1256
  throw e;
1284
1257
  });
@@ -1312,14 +1285,10 @@ ${gray("[vite-ssg]")} ${green("Build finished.")}`);
1312
1285
  timeout.unref();
1313
1286
  }
1314
1287
  function executeTaskInWorker(worker, opts) {
1315
- opts = Object.entries(opts).reduce((acc, [key, value]) => {
1316
- if (typeof value === "function")
1317
- return acc;
1318
- const newKey = key;
1319
- acc[newKey] = value;
1320
- return acc;
1321
- }, {});
1322
- return worker.send("executeTaskFn", [opts]);
1288
+ return execInWorker(worker, executeTaskFn, opts);
1289
+ }
1290
+ async function execInWorker(worker, fn, ...args) {
1291
+ return await worker.send(fn.name, plainify(args ?? []));
1323
1292
  }
1324
1293
  async function executeTaskFn(opts) {
1325
1294
  const {
@@ -1395,6 +1364,27 @@ async function executeTaskFn(opts) {
1395
1364
  ${err.stack}`);
1396
1365
  }
1397
1366
  }
1367
+ function plainify(m) {
1368
+ if (m instanceof Function) {
1369
+ return void 0;
1370
+ }
1371
+ if (Array.isArray(m)) {
1372
+ return m.map(plainify);
1373
+ }
1374
+ if (typeof m === "object" && m !== null) {
1375
+ if (m instanceof Error || "stack" in m) {
1376
+ return {
1377
+ message: m.message,
1378
+ stack: m.stack
1379
+ };
1380
+ }
1381
+ return Object.entries(m).reduce((acc, [key, value]) => {
1382
+ acc[key] = plainify(value);
1383
+ return acc;
1384
+ }, {});
1385
+ }
1386
+ return m;
1387
+ }
1398
1388
  async function detectEntry(root) {
1399
1389
  const scriptSrcReg = /<script.*?src=["'](.+?)["'](?!<).*>\s*<\/script>/gi;
1400
1390
  const html = await fs.readFile(join(root, "index.html"), "utf-8");
@@ -1493,4 +1483,4 @@ async function readFiles(...paths) {
1493
1483
  throw new Error(`Could not find any of the following files: ${paths.join(", ")}`);
1494
1484
  }
1495
1485
 
1496
- export { build as b, executeTaskFn as e, getBeastiesOrCritters as g };
1486
+ export { buildClient as a, build as b, buildServer as c, executeTaskFn as e, plainify as p };
@@ -839,35 +839,6 @@ class PQueue extends EventEmitter {
839
839
  }
840
840
  }
841
841
 
842
- async function getBeastiesOrCritters(outDir, options = {}) {
843
- try {
844
- const BeastiesClass = (await import('beasties')).default;
845
- return new BeastiesClass({
846
- path: outDir,
847
- logLevel: "warn",
848
- external: true,
849
- inlineFonts: true,
850
- preloadFonts: true,
851
- ...options
852
- });
853
- } catch {
854
- }
855
- try {
856
- const CrittersClass = (await import('critters')).default;
857
- console.warn("`critters` is deprecated. Please use `beasties` instead.");
858
- return new CrittersClass({
859
- path: outDir,
860
- logLevel: "warn",
861
- external: true,
862
- inlineFonts: true,
863
- preloadFonts: true,
864
- ...options
865
- });
866
- } catch {
867
- return void 0;
868
- }
869
- }
870
-
871
842
  function isMatchOption(node, opts) {
872
843
  if (opts.match.tag && !(node.name === opts.match.tag)) {
873
844
  return false;
@@ -1121,10 +1092,14 @@ async function buildClient(config, viteConfig) {
1121
1092
  mode: config.mode
1122
1093
  }));
1123
1094
  }
1124
- async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format }) {
1095
+ async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format, mock }) {
1125
1096
  buildLog("Build for server...");
1126
1097
  process__default.env.VITE_SSG = "true";
1127
1098
  const { base } = config;
1099
+ if (mock) {
1100
+ const { jsdomGlobal } = await import('../chunks/jsdomGlobal.cjs');
1101
+ jsdomGlobal();
1102
+ }
1128
1103
  await vite.build(vite.mergeConfig(viteConfig, {
1129
1104
  base,
1130
1105
  build: {
@@ -1145,6 +1120,19 @@ async function buildServer(config, viteConfig, { ssrEntry, ssgOut, format }) {
1145
1120
  mode: config.mode
1146
1121
  }));
1147
1122
  }
1123
+ function createProxy(options) {
1124
+ const workerExt = options.format === "esm" ? ".mjs" : ".cjs";
1125
+ const workerProxy = new BuildWorkerProxy(new URL(`./build.worker${workerExt}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.524d8794.cjs', document.baseURI).href))), {
1126
+ env: process__default.env,
1127
+ workerData: options
1128
+ });
1129
+ process__default.on("SIGINT", workerProxy.terminate.bind(workerProxy));
1130
+ process__default.on("SIGTERM", workerProxy.terminate.bind(workerProxy));
1131
+ process__default.on("SIGBREAK", workerProxy.terminate.bind(workerProxy));
1132
+ process__default.on("beforeExit", workerProxy.terminate.bind(workerProxy));
1133
+ process__default.on("exit", workerProxy.terminate.bind(workerProxy));
1134
+ return workerProxy;
1135
+ }
1148
1136
  async function build(ssgOptions = {}, viteConfig = {}) {
1149
1137
  const nodeEnv = process__default.env.NODE_ENV || "production";
1150
1138
  const mode = process__default.env.MODE || ssgOptions.mode || nodeEnv;
@@ -1174,6 +1162,42 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1174
1162
  rootContainerId = "app"
1175
1163
  } = Object.assign({}, config.ssgOptions || {}, ssgOptions);
1176
1164
  const ssgOut = node_path.isAbsolute(_ssgOutDir) ? _ssgOutDir : node_path.join(root, _ssgOutDir);
1165
+ const numberOfWorkers = Math.max(1, _numberOfWorkers);
1166
+ console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.blue(`Using ${numberOfWorkers} workers`)}`);
1167
+ const workers = Array.from({ length: numberOfWorkers }, (_, index) => createProxy({
1168
+ format,
1169
+ out,
1170
+ dirStyle,
1171
+ workerId: index,
1172
+ viteConfig: {
1173
+ configFile: config.configFile
1174
+ }
1175
+ }));
1176
+ const terminateWorkers = () => {
1177
+ workers.splice(0, workers.length).forEach((worker) => worker.terminate());
1178
+ };
1179
+ let workerIndex = 0;
1180
+ const maxTasksPerWorker = Math.ceil(concurrency / numberOfWorkers);
1181
+ const workersInUse = /* @__PURE__ */ new Map();
1182
+ const workerTasksRunning = (w) => workersInUse.get(w)?.length || 0;
1183
+ const selectIdleWorker = () => workers.filter((w) => workerTasksRunning(w) < maxTasksPerWorker).sort((a, b) => workerTasksRunning(a) - workerTasksRunning(b))[0];
1184
+ const selectWorker = async (workerIndex2) => {
1185
+ const index = workerIndex2 ?? Math.round(Math.random() * numberOfWorkers);
1186
+ const maybeWorker = workers[index % numberOfWorkers];
1187
+ const worker = maybeWorker && workerTasksRunning(maybeWorker) < maxTasksPerWorker ? maybeWorker : selectIdleWorker();
1188
+ if (!worker) {
1189
+ await Promise.race(Array.from(workersInUse.values()).flat());
1190
+ return selectWorker(workerIndex2);
1191
+ }
1192
+ const workerPromises = workersInUse.get(worker) || [];
1193
+ const delayPromise = new Promise((resolve) => setImmediate(resolve));
1194
+ workersInUse.set(worker, [...workerPromises, delayPromise]);
1195
+ delayPromise.finally(() => {
1196
+ workerPromises.splice(workerPromises.indexOf(delayPromise), 1);
1197
+ workersInUse.set(worker, workerPromises);
1198
+ });
1199
+ return worker;
1200
+ };
1177
1201
  let willRunBuild = true;
1178
1202
  if (fs__default.existsSync(ssgOut)) {
1179
1203
  willRunBuild = !ssgOptions["skip-build"];
@@ -1181,28 +1205,25 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1181
1205
  await fs__default.remove(ssgOut);
1182
1206
  }
1183
1207
  }
1184
- if (willRunBuild)
1185
- await buildClient(config, viteConfig);
1186
- if (mock) {
1187
- const { jsdomGlobal } = await import('../chunks/jsdomGlobal.cjs');
1188
- jsdomGlobal();
1208
+ if (willRunBuild) {
1209
+ const clientWorker = await selectWorker(0);
1210
+ await execInWorker(clientWorker, buildClient, config, viteConfig);
1189
1211
  }
1190
1212
  const ssrEntry = await resolveAlias(config, entry);
1191
- if (willRunBuild)
1192
- await buildServer(config, viteConfig, { ssrEntry, ssgOut, format });
1213
+ if (willRunBuild) {
1214
+ const serverWorker = await selectWorker(1);
1215
+ await execInWorker(serverWorker, buildServer, config, viteConfig, { ssrEntry, ssgOut, format, mock });
1216
+ }
1193
1217
  const prefix = format === "esm" && process__default.platform === "win32" ? "file://" : "";
1194
1218
  const ext = format === "esm" ? ".mjs" : ".cjs";
1195
1219
  const serverEntry = prefix + node_path.join(ssgOut, node_path.parse(ssrEntry).name + ext).replace(/\\/g, "/");
1196
- const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.3da368f4.cjs', document.baseURI).href)));
1220
+ const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.524d8794.cjs', document.baseURI).href)));
1197
1221
  const { createApp, includedRoutes: serverEntryIncludedRoutes } = format === "esm" ? await import(serverEntry) : _require(serverEntry);
1198
1222
  const includedRoutes = serverEntryIncludedRoutes || configIncludedRoutes;
1199
1223
  const { routes } = await createApp(false);
1200
1224
  let routesPaths = includeAllRoutes ? routesToPaths(routes) : await includedRoutes(routesToPaths(routes), routes || []);
1201
1225
  routesPaths = Array.from(new Set(routesPaths));
1202
1226
  buildLog("Rendering Pages...", routesPaths.length);
1203
- const beasties = beastiesOptions !== false ? await getBeastiesOrCritters(outDir, beastiesOptions) : void 0;
1204
- if (beasties)
1205
- console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.blue("Critical CSS generation enabled via `beasties`")}`);
1206
1227
  const {
1207
1228
  path: _ssrManifestPath,
1208
1229
  content: ssrManifestRaw
@@ -1218,76 +1239,28 @@ async function build(ssgOptions = {}, viteConfig = {}) {
1218
1239
  const IS_PROD = nodeEnv === "production";
1219
1240
  indexHTML = await formatHtml(indexHTML, IS_PROD ? "minify" : formatting, minifyOptions);
1220
1241
  const queue = new PQueue({ concurrency });
1221
- const workerExt = format === "esm" ? ".mjs" : ".cjs";
1222
- const createProxy = (index) => {
1223
- const workerProxy = new BuildWorkerProxy(new URL(`./build.worker${workerExt}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/vite-ssg-optimized.3da368f4.cjs', document.baseURI).href))), {
1224
- env: process__default.env,
1225
- workerData: {
1226
- workerId: index,
1227
- serverEntry,
1228
- ssrManifest,
1229
- format,
1230
- out,
1231
- beastiesOptions,
1232
- dirStyle,
1233
- indexHTML,
1234
- rootContainerId,
1235
- formatting,
1236
- minifyOptions,
1237
- viteConfig: {
1238
- configFile: config.configFile
1239
- }
1240
- }
1241
- });
1242
- return workerProxy;
1243
- };
1244
- const numberOfWorkers = Math.max(1, _numberOfWorkers);
1245
- console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.blue(`Using ${numberOfWorkers} workers`)}`);
1246
- const workers = Array.from({ length: numberOfWorkers }, (_, index) => createProxy(index));
1247
- const terminateWorkers = () => {
1248
- workers.splice(0, workers.length).forEach((worker) => worker.terminate());
1249
- };
1250
- process__default.on("SIGINT", terminateWorkers);
1251
- process__default.on("SIGTERM", terminateWorkers);
1252
- process__default.on("SIGBREAK", terminateWorkers);
1253
- process__default.on("beforeExit", terminateWorkers);
1254
- process__default.on("exit", terminateWorkers);
1255
- let workerIndex = 0;
1256
- const maxTasksPerWorker = Math.ceil(concurrency / numberOfWorkers);
1257
- const workersInUse = /* @__PURE__ */ new Map();
1258
- const workerTasksRunning = (w) => workersInUse.get(w)?.length || 0;
1259
- const selectIdleWorker = () => workers.filter((w) => workerTasksRunning(w) < maxTasksPerWorker).sort((a, b) => workerTasksRunning(a) - workerTasksRunning(b))[0];
1260
- const selectWorker = async (workerIndex2) => {
1261
- const index = workerIndex2 ?? Math.round(Math.random() * numberOfWorkers);
1262
- const maybeWorker = workers[index % numberOfWorkers];
1263
- const worker = maybeWorker && workerTasksRunning(maybeWorker) < maxTasksPerWorker ? maybeWorker : selectIdleWorker();
1264
- if (!worker) {
1265
- await Promise.race(Array.from(workersInUse.values()).flat());
1266
- return selectWorker(workerIndex2);
1267
- }
1268
- const workerPromises = workersInUse.get(worker) || [];
1269
- const delayPromise = new Promise((resolve) => setImmediate(resolve));
1270
- workersInUse.set(worker, [...workerPromises, delayPromise]);
1271
- delayPromise.finally(() => {
1272
- workerPromises.splice(workerPromises.indexOf(delayPromise), 1);
1273
- workersInUse.set(worker, workerPromises);
1274
- });
1275
- return worker;
1276
- };
1277
1242
  for (const route of routesPaths) {
1278
1243
  await queue.onSizeLessThan(concurrency);
1279
1244
  queue.add(async () => {
1280
1245
  const workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
1281
1246
  let retryCount = 0;
1282
1247
  const maxRetries = 3;
1283
- const taskPromise = executeTaskInWorker(workerProxy, {
1284
- route
1285
- }).catch((e) => {
1248
+ const execOpts = {
1249
+ route,
1250
+ ssrManifest,
1251
+ indexHTML,
1252
+ rootContainerId,
1253
+ formatting,
1254
+ minifyOptions,
1255
+ // out,
1256
+ // dirStyle,
1257
+ beastiesOptions,
1258
+ serverEntry
1259
+ };
1260
+ const taskPromise = executeTaskInWorker(workerProxy, execOpts).catch((e) => {
1286
1261
  if (retryCount++ < maxRetries) {
1287
1262
  console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.yellow(`Retrying ${retryCount} of ${maxRetries} for route: ${kolorist.cyan(route)}`)}`);
1288
- return executeTaskInWorker(workerProxy, {
1289
- route
1290
- });
1263
+ return executeTaskInWorker(workerProxy, execOpts);
1291
1264
  }
1292
1265
  throw e;
1293
1266
  });
@@ -1321,14 +1294,10 @@ ${kolorist.gray("[vite-ssg]")} ${kolorist.green("Build finished.")}`);
1321
1294
  timeout.unref();
1322
1295
  }
1323
1296
  function executeTaskInWorker(worker, opts) {
1324
- opts = Object.entries(opts).reduce((acc, [key, value]) => {
1325
- if (typeof value === "function")
1326
- return acc;
1327
- const newKey = key;
1328
- acc[newKey] = value;
1329
- return acc;
1330
- }, {});
1331
- return worker.send("executeTaskFn", [opts]);
1297
+ return execInWorker(worker, executeTaskFn, opts);
1298
+ }
1299
+ async function execInWorker(worker, fn, ...args) {
1300
+ return await worker.send(fn.name, plainify(args ?? []));
1332
1301
  }
1333
1302
  async function executeTaskFn(opts) {
1334
1303
  const {
@@ -1404,6 +1373,27 @@ async function executeTaskFn(opts) {
1404
1373
  ${err.stack}`);
1405
1374
  }
1406
1375
  }
1376
+ function plainify(m) {
1377
+ if (m instanceof Function) {
1378
+ return void 0;
1379
+ }
1380
+ if (Array.isArray(m)) {
1381
+ return m.map(plainify);
1382
+ }
1383
+ if (typeof m === "object" && m !== null) {
1384
+ if (m instanceof Error || "stack" in m) {
1385
+ return {
1386
+ message: m.message,
1387
+ stack: m.stack
1388
+ };
1389
+ }
1390
+ return Object.entries(m).reduce((acc, [key, value]) => {
1391
+ acc[key] = plainify(value);
1392
+ return acc;
1393
+ }, {});
1394
+ }
1395
+ return m;
1396
+ }
1407
1397
  async function detectEntry(root) {
1408
1398
  const scriptSrcReg = /<script.*?src=["'](.+?)["'](?!<).*>\s*<\/script>/gi;
1409
1399
  const html = await fs__default.readFile(node_path.join(root, "index.html"), "utf-8");
@@ -1503,5 +1493,7 @@ async function readFiles(...paths) {
1503
1493
  }
1504
1494
 
1505
1495
  exports.build = build;
1496
+ exports.buildClient = buildClient;
1497
+ exports.buildServer = buildServer;
1506
1498
  exports.executeTaskFn = executeTaskFn;
1507
- exports.getBeastiesOrCritters = getBeastiesOrCritters;
1499
+ exports.plainify = plainify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-ssg-optimized",
3
- "version": "0.24.2-optimized.22",
3
+ "version": "0.24.2-optimized.23",
4
4
  "description": "Server-side generation for Vite",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -1,9 +0,0 @@
1
- import { InlineConfig } from 'vite';
2
- import { b as ViteSSGOptions } from './vite-ssg-optimized.341e382e.cjs';
3
-
4
- type Manifest = Record<string, string[]>;
5
- declare function build(ssgOptions?: Partial<ViteSSGOptions & {
6
- 'skip-build'?: boolean;
7
- }>, viteConfig?: InlineConfig): Promise<void>;
8
-
9
- export { type Manifest as M, build as b };
@@ -1,9 +0,0 @@
1
- import { InlineConfig } from 'vite';
2
- import { b as ViteSSGOptions } from './vite-ssg-optimized.341e382e.mjs';
3
-
4
- type Manifest = Record<string, string[]>;
5
- declare function build(ssgOptions?: Partial<ViteSSGOptions & {
6
- 'skip-build'?: boolean;
7
- }>, viteConfig?: InlineConfig): Promise<void>;
8
-
9
- export { type Manifest as M, build as b };
@@ -1,9 +0,0 @@
1
- import { InlineConfig } from 'vite';
2
- import { b as ViteSSGOptions } from './vite-ssg-optimized.341e382e.js';
3
-
4
- type Manifest = Record<string, string[]>;
5
- declare function build(ssgOptions?: Partial<ViteSSGOptions & {
6
- 'skip-build'?: boolean;
7
- }>, viteConfig?: InlineConfig): Promise<void>;
8
-
9
- export { type Manifest as M, build as b };