vite-ssg-optimized 0.24.2-optimized.21 → 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 +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +8 -3
- package/dist/node.d.mts +8 -3
- package/dist/node.d.ts +8 -3
- package/dist/node.mjs +1 -1
- package/dist/shared/build.worker.cjs +53 -34
- package/dist/shared/build.worker.d.cts +3 -13
- package/dist/shared/build.worker.d.mts +3 -13
- package/dist/shared/build.worker.d.ts +3 -13
- package/dist/shared/build.worker.mjs +54 -35
- package/dist/shared/{vite-ssg-optimized.22da6b90.mjs → vite-ssg-optimized.2fd44d5b.mjs} +106 -106
- package/dist/shared/{vite-ssg-optimized.79d27333.cjs → vite-ssg-optimized.524d8794.cjs} +108 -106
- package/package.json +1 -1
- package/dist/shared/vite-ssg-optimized.27bed688.d.cts +0 -9
- package/dist/shared/vite-ssg-optimized.f03a17e6.d.mts +0 -9
- package/dist/shared/vite-ssg-optimized.f1a9229c.d.ts +0 -9
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.
|
|
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.
|
|
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
package/dist/node.d.cts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -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.
|
|
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(
|
|
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 {
|
|
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
|
-
|
|
91
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
4
|
-
import { gray, blue
|
|
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(
|
|
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 {
|
|
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
|
-
|
|
88
|
-
|
|
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();
|
|
@@ -3,7 +3,7 @@ import { isAbsolute, join, parse, dirname } from 'node:path';
|
|
|
3
3
|
import process$1 from 'node:process';
|
|
4
4
|
import { renderSSRHead } from '@unhead/ssr';
|
|
5
5
|
import fs from 'fs-extra';
|
|
6
|
-
import { gray, yellow, blue, reset, green, dim,
|
|
6
|
+
import { gray, yellow, blue, reset, cyan, green, dim, red } from 'kolorist';
|
|
7
7
|
import { resolveConfig, build as build$1, mergeConfig } from 'vite';
|
|
8
8
|
import { s as serializeState } from './vite-ssg-optimized.579feabb.mjs';
|
|
9
9
|
import html5Parser, { SyntaxKind } from 'html5parser';
|
|
@@ -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
|
|
1177
|
-
|
|
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
|
-
|
|
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,68 +1230,30 @@ 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
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1233
|
+
for (const route of routesPaths) {
|
|
1234
|
+
await queue.onSizeLessThan(concurrency);
|
|
1235
|
+
queue.add(async () => {
|
|
1236
|
+
const workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
|
|
1237
|
+
let retryCount = 0;
|
|
1238
|
+
const maxRetries = 3;
|
|
1239
|
+
const execOpts = {
|
|
1240
|
+
route,
|
|
1219
1241
|
ssrManifest,
|
|
1220
|
-
format,
|
|
1221
|
-
out,
|
|
1222
|
-
beastiesOptions,
|
|
1223
|
-
dirStyle,
|
|
1224
1242
|
indexHTML,
|
|
1225
1243
|
rootContainerId,
|
|
1226
1244
|
formatting,
|
|
1227
1245
|
minifyOptions,
|
|
1228
|
-
|
|
1229
|
-
|
|
1246
|
+
// out,
|
|
1247
|
+
// dirStyle,
|
|
1248
|
+
beastiesOptions,
|
|
1249
|
+
serverEntry
|
|
1250
|
+
};
|
|
1251
|
+
const taskPromise = executeTaskInWorker(workerProxy, execOpts).catch((e) => {
|
|
1252
|
+
if (retryCount++ < maxRetries) {
|
|
1253
|
+
console.log(`${gray("[vite-ssg]")} ${yellow(`Retrying ${retryCount} of ${maxRetries} for route: ${cyan(route)}`)}`);
|
|
1254
|
+
return executeTaskInWorker(workerProxy, execOpts);
|
|
1230
1255
|
}
|
|
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
|
-
for (const route of routesPaths) {
|
|
1269
|
-
await queue.onSizeLessThan(concurrency);
|
|
1270
|
-
queue.add(async () => {
|
|
1271
|
-
const workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
|
|
1272
|
-
const taskPromise = executeTaskInWorker(workerProxy, {
|
|
1273
|
-
route
|
|
1256
|
+
throw e;
|
|
1274
1257
|
});
|
|
1275
1258
|
const workerPromises = workersInUse.get(workerProxy) || [];
|
|
1276
1259
|
workersInUse.set(workerProxy, workerPromises);
|
|
@@ -1302,14 +1285,10 @@ ${gray("[vite-ssg]")} ${green("Build finished.")}`);
|
|
|
1302
1285
|
timeout.unref();
|
|
1303
1286
|
}
|
|
1304
1287
|
function executeTaskInWorker(worker, opts) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
acc[newKey] = value;
|
|
1310
|
-
return acc;
|
|
1311
|
-
}, {});
|
|
1312
|
-
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 ?? []));
|
|
1313
1292
|
}
|
|
1314
1293
|
async function executeTaskFn(opts) {
|
|
1315
1294
|
const {
|
|
@@ -1385,6 +1364,27 @@ async function executeTaskFn(opts) {
|
|
|
1385
1364
|
${err.stack}`);
|
|
1386
1365
|
}
|
|
1387
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
|
+
}
|
|
1388
1388
|
async function detectEntry(root) {
|
|
1389
1389
|
const scriptSrcReg = /<script.*?src=["'](.+?)["'](?!<).*>\s*<\/script>/gi;
|
|
1390
1390
|
const html = await fs.readFile(join(root, "index.html"), "utf-8");
|
|
@@ -1483,4 +1483,4 @@ async function readFiles(...paths) {
|
|
|
1483
1483
|
throw new Error(`Could not find any of the following files: ${paths.join(", ")}`);
|
|
1484
1484
|
}
|
|
1485
1485
|
|
|
1486
|
-
export { build as b, executeTaskFn as e,
|
|
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
|
|
1186
|
-
|
|
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
|
-
|
|
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.
|
|
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,68 +1239,30 @@ 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
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1242
|
+
for (const route of routesPaths) {
|
|
1243
|
+
await queue.onSizeLessThan(concurrency);
|
|
1244
|
+
queue.add(async () => {
|
|
1245
|
+
const workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
|
|
1246
|
+
let retryCount = 0;
|
|
1247
|
+
const maxRetries = 3;
|
|
1248
|
+
const execOpts = {
|
|
1249
|
+
route,
|
|
1228
1250
|
ssrManifest,
|
|
1229
|
-
format,
|
|
1230
|
-
out,
|
|
1231
|
-
beastiesOptions,
|
|
1232
|
-
dirStyle,
|
|
1233
1251
|
indexHTML,
|
|
1234
1252
|
rootContainerId,
|
|
1235
1253
|
formatting,
|
|
1236
1254
|
minifyOptions,
|
|
1237
|
-
|
|
1238
|
-
|
|
1255
|
+
// out,
|
|
1256
|
+
// dirStyle,
|
|
1257
|
+
beastiesOptions,
|
|
1258
|
+
serverEntry
|
|
1259
|
+
};
|
|
1260
|
+
const taskPromise = executeTaskInWorker(workerProxy, execOpts).catch((e) => {
|
|
1261
|
+
if (retryCount++ < maxRetries) {
|
|
1262
|
+
console.log(`${kolorist.gray("[vite-ssg]")} ${kolorist.yellow(`Retrying ${retryCount} of ${maxRetries} for route: ${kolorist.cyan(route)}`)}`);
|
|
1263
|
+
return executeTaskInWorker(workerProxy, execOpts);
|
|
1239
1264
|
}
|
|
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
|
-
for (const route of routesPaths) {
|
|
1278
|
-
await queue.onSizeLessThan(concurrency);
|
|
1279
|
-
queue.add(async () => {
|
|
1280
|
-
const workerProxy = await selectWorker(workerIndex++ % numberOfWorkers);
|
|
1281
|
-
const taskPromise = executeTaskInWorker(workerProxy, {
|
|
1282
|
-
route
|
|
1265
|
+
throw e;
|
|
1283
1266
|
});
|
|
1284
1267
|
const workerPromises = workersInUse.get(workerProxy) || [];
|
|
1285
1268
|
workersInUse.set(workerProxy, workerPromises);
|
|
@@ -1311,14 +1294,10 @@ ${kolorist.gray("[vite-ssg]")} ${kolorist.green("Build finished.")}`);
|
|
|
1311
1294
|
timeout.unref();
|
|
1312
1295
|
}
|
|
1313
1296
|
function executeTaskInWorker(worker, opts) {
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
acc[newKey] = value;
|
|
1319
|
-
return acc;
|
|
1320
|
-
}, {});
|
|
1321
|
-
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 ?? []));
|
|
1322
1301
|
}
|
|
1323
1302
|
async function executeTaskFn(opts) {
|
|
1324
1303
|
const {
|
|
@@ -1394,6 +1373,27 @@ async function executeTaskFn(opts) {
|
|
|
1394
1373
|
${err.stack}`);
|
|
1395
1374
|
}
|
|
1396
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
|
+
}
|
|
1397
1397
|
async function detectEntry(root) {
|
|
1398
1398
|
const scriptSrcReg = /<script.*?src=["'](.+?)["'](?!<).*>\s*<\/script>/gi;
|
|
1399
1399
|
const html = await fs__default.readFile(node_path.join(root, "index.html"), "utf-8");
|
|
@@ -1493,5 +1493,7 @@ async function readFiles(...paths) {
|
|
|
1493
1493
|
}
|
|
1494
1494
|
|
|
1495
1495
|
exports.build = build;
|
|
1496
|
+
exports.buildClient = buildClient;
|
|
1497
|
+
exports.buildServer = buildServer;
|
|
1496
1498
|
exports.executeTaskFn = executeTaskFn;
|
|
1497
|
-
exports.
|
|
1499
|
+
exports.plainify = plainify;
|
package/package.json
CHANGED
|
@@ -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 };
|