@analogjs/vite-plugin-nitro 3.0.0-alpha.4 → 3.0.0-alpha.41
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/package.json +26 -11
- package/src/index.d.ts +11 -9
- package/src/index.js +7 -2
- package/src/index.js.map +1 -1
- package/src/lib/build-server.d.ts +2 -2
- package/src/lib/build-server.js +45 -149
- package/src/lib/build-server.js.map +1 -1
- package/src/lib/build-sitemap.d.ts +23 -9
- package/src/lib/build-sitemap.js +132 -63
- package/src/lib/build-sitemap.js.map +1 -1
- package/src/lib/build-ssr.d.ts +3 -2
- package/src/lib/build-ssr.js +26 -18
- package/src/lib/build-ssr.js.map +1 -1
- package/src/lib/hooks/post-rendering-hook.d.ts +1 -1
- package/src/lib/hooks/post-rendering-hook.js +10 -6
- package/src/lib/hooks/post-rendering-hook.js.map +1 -1
- package/src/lib/options.d.ts +143 -106
- package/src/lib/plugins/dev-server-plugin.d.ts +3 -3
- package/src/lib/plugins/dev-server-plugin.js +98 -101
- package/src/lib/plugins/dev-server-plugin.js.map +1 -1
- package/src/lib/plugins/page-endpoints.d.ts +5 -5
- package/src/lib/plugins/page-endpoints.js +26 -57
- package/src/lib/plugins/page-endpoints.js.map +1 -1
- package/src/lib/utils/debug.d.ts +5 -0
- package/src/lib/utils/debug.js +15 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/get-content-files.d.ts +54 -54
- package/src/lib/utils/get-content-files.js +88 -97
- package/src/lib/utils/get-content-files.js.map +1 -1
- package/src/lib/utils/get-page-handlers.d.ts +58 -58
- package/src/lib/utils/get-page-handlers.js +70 -84
- package/src/lib/utils/get-page-handlers.js.map +1 -1
- package/src/lib/utils/i18n-prerender.d.ts +36 -0
- package/src/lib/utils/i18n-prerender.js +23 -0
- package/src/lib/utils/i18n-prerender.js.map +1 -0
- package/src/lib/utils/load-esm.d.ts +18 -18
- package/src/lib/utils/node-web-bridge.d.ts +1 -1
- package/src/lib/utils/node-web-bridge.js +50 -45
- package/src/lib/utils/node-web-bridge.js.map +1 -1
- package/src/lib/utils/register-dev-middleware.d.ts +12 -12
- package/src/lib/utils/register-dev-middleware.js +41 -47
- package/src/lib/utils/register-dev-middleware.js.map +1 -1
- package/src/lib/utils/register-i18n-watcher.d.ts +15 -0
- package/src/lib/utils/renderers.d.ts +47 -47
- package/src/lib/utils/renderers.js +57 -56
- package/src/lib/utils/renderers.js.map +1 -1
- package/src/lib/utils/rolldown.d.ts +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- package/src/lib/vite-plugin-nitro.d.ts +3 -3
- package/src/lib/vite-plugin-nitro.js +790 -677
- package/src/lib/vite-plugin-nitro.js.map +1 -1
- package/README.md +0 -125
- package/src/lib/options.js +0 -2
- package/src/lib/options.js.map +0 -1
- package/src/lib/utils/load-esm.js +0 -23
- package/src/lib/utils/load-esm.js.map +0 -1
|
@@ -1,705 +1,818 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import { buildServer, isVercelPreset } from "./build-server.js";
|
|
2
|
+
import { getBundleOptionsKey, isRolldown } from "./utils/rolldown.js";
|
|
3
|
+
import { buildClientApp, buildSSRApp } from "./build-ssr.js";
|
|
4
|
+
import { apiMiddleware, clientRenderer, ssrRenderer } from "./utils/renderers.js";
|
|
5
|
+
import { pageEndpointsPlugin } from "./plugins/page-endpoints.js";
|
|
6
|
+
import { getPageHandlers } from "./utils/get-page-handlers.js";
|
|
7
|
+
import { buildSitemap } from "./build-sitemap.js";
|
|
8
|
+
import { toWebRequest, writeWebResponseToNode } from "./utils/node-web-bridge.js";
|
|
9
|
+
import { devServerPlugin } from "./plugins/dev-server-plugin.js";
|
|
10
|
+
import { getMatchingContentFilesWithFrontMatter } from "./utils/get-content-files.js";
|
|
11
|
+
import { debugNitro, debugSsr } from "./utils/debug.js";
|
|
12
|
+
import { build, createDevServer, createNitro } from "nitro/builder";
|
|
13
|
+
import { mergeConfig, normalizePath } from "vite";
|
|
14
|
+
import { relative, resolve } from "node:path";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
16
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
17
|
+
//#region packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts
|
|
18
|
+
function isObjectHook(value) {
|
|
19
|
+
return !!value && typeof value === "object" && "handler" in value;
|
|
20
|
+
}
|
|
21
|
+
function cloneObjectHook(hook) {
|
|
22
|
+
if (!isObjectHook(hook)) return hook;
|
|
23
|
+
return {
|
|
24
|
+
...hook,
|
|
25
|
+
handler: hook.handler
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function cloneUserPlugin(plugin) {
|
|
29
|
+
if (!plugin || typeof plugin !== "object") return plugin;
|
|
30
|
+
const pluginRecord = plugin;
|
|
31
|
+
const clone = Object.assign(Object.create(Object.getPrototypeOf(plugin)), pluginRecord);
|
|
32
|
+
for (const key of Object.keys(pluginRecord)) clone[key] = cloneObjectHook(pluginRecord[key]);
|
|
33
|
+
return clone;
|
|
34
|
+
}
|
|
35
|
+
function cloneEnvironmentEntries(environments) {
|
|
36
|
+
if (!environments || typeof environments !== "object") return environments;
|
|
37
|
+
return Object.fromEntries(Object.entries(environments).map(([name, environment]) => {
|
|
38
|
+
if (!environment || typeof environment !== "object") return [name, environment];
|
|
39
|
+
const environmentRecord = environment;
|
|
40
|
+
return [name, {
|
|
41
|
+
...environmentRecord,
|
|
42
|
+
build: environmentRecord["build"] && typeof environmentRecord["build"] === "object" ? { ...environmentRecord["build"] } : environmentRecord["build"]
|
|
43
|
+
}];
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
function cloneUserConfig(userConfig) {
|
|
47
|
+
const { environments, resolve, build, server, plugins } = userConfig;
|
|
48
|
+
const test = userConfig.test;
|
|
49
|
+
return {
|
|
50
|
+
...userConfig,
|
|
51
|
+
plugins: plugins?.map(cloneUserPlugin),
|
|
52
|
+
build: build && { ...build },
|
|
53
|
+
environments: cloneEnvironmentEntries(environments),
|
|
54
|
+
server: server && { ...server },
|
|
55
|
+
test: test && { ...test },
|
|
56
|
+
resolve: resolve && {
|
|
57
|
+
...resolve,
|
|
58
|
+
alias: Array.isArray(resolve.alias) ? [...resolve.alias] : resolve.alias && typeof resolve.alias === "object" ? { ...resolve.alias } : resolve.alias
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
16
62
|
function createNitroMiddlewareHandler(handler) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
63
|
+
return {
|
|
64
|
+
route: "/**",
|
|
65
|
+
handler,
|
|
66
|
+
middleware: true
|
|
67
|
+
};
|
|
22
68
|
}
|
|
23
69
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
70
|
+
* Creates a `rollup:before` hook that marks specified packages as external
|
|
71
|
+
* in Nitro's bundler config (applied to both the server build and the
|
|
72
|
+
* prerender build).
|
|
73
|
+
*
|
|
74
|
+
* ## Subpath matching (Rolldown compatibility)
|
|
75
|
+
*
|
|
76
|
+
* When `bundlerConfig.external` is an **array**, Rollup automatically
|
|
77
|
+
* prefix-matches entries — `'rxjs'` in the array will also externalise
|
|
78
|
+
* `'rxjs/operators'`, `'rxjs/internal/Observable'`, etc.
|
|
79
|
+
*
|
|
80
|
+
* Rolldown (the default bundler in Nitro v3) does **not** do this. It
|
|
81
|
+
* treats array entries as exact strings. To keep behaviour consistent
|
|
82
|
+
* across both bundlers, the **function** branch already needed explicit
|
|
83
|
+
* subpath matching. We now use the same `isExternal` helper for all
|
|
84
|
+
* branches so that `'rxjs'` reliably matches `'rxjs/operators'`
|
|
85
|
+
* regardless of whether the existing `external` value is a function,
|
|
86
|
+
* array, or absent.
|
|
87
|
+
*
|
|
88
|
+
* Without this, the Nitro prerender build fails on Windows CI with:
|
|
89
|
+
*
|
|
90
|
+
* [RESOLVE_ERROR] Could not resolve 'rxjs/operators'
|
|
91
|
+
*/
|
|
46
92
|
function createRollupBeforeHook(externalEntries) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
else if (typeof existing === 'function') {
|
|
58
|
-
bundlerConfig.external = (source, importer, isResolved) => existing(source, importer, isResolved) || isExternal(source);
|
|
59
|
-
}
|
|
60
|
-
else if (Array.isArray(existing)) {
|
|
61
|
-
bundlerConfig.external = [...existing, ...externalEntries];
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
bundlerConfig.external = [existing, ...externalEntries];
|
|
65
|
-
}
|
|
66
|
-
};
|
|
93
|
+
const isExternal = (source) => externalEntries.some((entry) => source === entry || source.startsWith(entry + "/"));
|
|
94
|
+
return (_nitro, bundlerConfig) => {
|
|
95
|
+
sanitizeNitroBundlerConfig(_nitro, bundlerConfig);
|
|
96
|
+
if (externalEntries.length === 0) return;
|
|
97
|
+
const existing = bundlerConfig.external;
|
|
98
|
+
if (!existing) bundlerConfig.external = externalEntries;
|
|
99
|
+
else if (typeof existing === "function") bundlerConfig.external = (source, importer, isResolved) => existing(source, importer, isResolved) || isExternal(source);
|
|
100
|
+
else if (Array.isArray(existing)) bundlerConfig.external = [...existing, ...externalEntries];
|
|
101
|
+
else bundlerConfig.external = [existing, ...externalEntries];
|
|
102
|
+
};
|
|
67
103
|
}
|
|
68
104
|
function appendNoExternals(noExternals, ...entries) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
return Array.isArray(noExternals)
|
|
73
|
-
? [...noExternals, ...entries]
|
|
74
|
-
: noExternals;
|
|
105
|
+
if (!noExternals) return entries;
|
|
106
|
+
return Array.isArray(noExternals) ? [...noExternals, ...entries] : noExternals;
|
|
75
107
|
}
|
|
76
108
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
109
|
+
* Patches Nitro's internal Rollup/Rolldown bundler config to work around
|
|
110
|
+
* incompatibilities in the Nitro v3 alpha series.
|
|
111
|
+
*
|
|
112
|
+
* Called from the `rollup:before` hook, this function runs against the *final*
|
|
113
|
+
* bundler config that Nitro assembles for its server/prerender builds — it
|
|
114
|
+
* does NOT touch the normal Vite client or SSR environment configs.
|
|
115
|
+
*
|
|
116
|
+
* Each workaround is narrowly scoped and safe to remove once the corresponding
|
|
117
|
+
* upstream Nitro issue is resolved.
|
|
118
|
+
*/
|
|
87
119
|
function sanitizeNitroBundlerConfig(_nitro, bundlerConfig) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
120
|
+
const output = bundlerConfig["output"];
|
|
121
|
+
if (!output || Array.isArray(output) || typeof output !== "object") return;
|
|
122
|
+
if ("codeSplitting" in output) delete output["codeSplitting"];
|
|
123
|
+
if ("manualChunks" in output) delete output["manualChunks"];
|
|
124
|
+
const VALID_ROLLUP_PLACEHOLDER = /^\[(?:name|hash|format|ext)\]$/;
|
|
125
|
+
const chunkFileNames = output["chunkFileNames"];
|
|
126
|
+
if (typeof chunkFileNames === "function") {
|
|
127
|
+
const originalFn = chunkFileNames;
|
|
128
|
+
output["chunkFileNames"] = (...args) => {
|
|
129
|
+
const result = originalFn(...args);
|
|
130
|
+
if (typeof result !== "string") return result;
|
|
131
|
+
return result.replace(/\[[^\]]+\]/g, (match) => VALID_ROLLUP_PLACEHOLDER.test(match) ? match : `_${match.slice(1, -1)}_`);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function resolveClientOutputPath(cachedPath, workspaceRoot, rootDir, configuredOutDir) {
|
|
136
|
+
if (cachedPath) {
|
|
137
|
+
debugNitro("resolveClientOutputPath using cached path", {
|
|
138
|
+
cachedPath,
|
|
139
|
+
workspaceRoot,
|
|
140
|
+
rootDir,
|
|
141
|
+
configuredOutDir
|
|
142
|
+
});
|
|
143
|
+
return cachedPath;
|
|
144
|
+
}
|
|
145
|
+
if (configuredOutDir) {
|
|
146
|
+
const resolvedPath = normalizePath(resolve(workspaceRoot, rootDir, configuredOutDir));
|
|
147
|
+
debugNitro("resolveClientOutputPath using configured build.outDir", {
|
|
148
|
+
workspaceRoot,
|
|
149
|
+
rootDir,
|
|
150
|
+
configuredOutDir,
|
|
151
|
+
resolvedPath
|
|
152
|
+
});
|
|
153
|
+
return resolvedPath;
|
|
154
|
+
}
|
|
155
|
+
const resolvedPath = normalizePath(resolve(workspaceRoot, "dist", rootDir, "client"));
|
|
156
|
+
debugNitro("resolveClientOutputPath using default dist client path", {
|
|
157
|
+
workspaceRoot,
|
|
158
|
+
rootDir,
|
|
159
|
+
configuredOutDir,
|
|
160
|
+
resolvedPath
|
|
161
|
+
});
|
|
162
|
+
return resolvedPath;
|
|
163
|
+
}
|
|
164
|
+
function getEnvironmentBuildOutDir(environment) {
|
|
165
|
+
if (!environment || typeof environment !== "object") return;
|
|
166
|
+
const environmentConfig = environment;
|
|
167
|
+
return environmentConfig.config?.build?.outDir ?? environmentConfig.build?.outDir;
|
|
168
|
+
}
|
|
169
|
+
function resolveBuiltClientOutputPath(cachedPath, workspaceRoot, rootDir, configuredOutDir, environment) {
|
|
170
|
+
const environmentOutDir = getEnvironmentBuildOutDir(environment);
|
|
171
|
+
if (environmentOutDir) {
|
|
172
|
+
const resolvedPath = normalizePath(resolve(workspaceRoot, rootDir, environmentOutDir));
|
|
173
|
+
debugNitro("resolveBuiltClientOutputPath using environment outDir", {
|
|
174
|
+
cachedPath,
|
|
175
|
+
workspaceRoot,
|
|
176
|
+
rootDir,
|
|
177
|
+
configuredOutDir,
|
|
178
|
+
environmentOutDir,
|
|
179
|
+
resolvedPath
|
|
180
|
+
});
|
|
181
|
+
return resolvedPath;
|
|
182
|
+
}
|
|
183
|
+
debugNitro("resolveBuiltClientOutputPath falling back to shared resolver", {
|
|
184
|
+
cachedPath,
|
|
185
|
+
workspaceRoot,
|
|
186
|
+
rootDir,
|
|
187
|
+
configuredOutDir,
|
|
188
|
+
environmentOutDir
|
|
189
|
+
});
|
|
190
|
+
return resolveClientOutputPath(cachedPath, workspaceRoot, rootDir, configuredOutDir);
|
|
191
|
+
}
|
|
192
|
+
function getNitroPublicOutputDir(nitroConfig) {
|
|
193
|
+
const publicDir = nitroConfig.output?.publicDir;
|
|
194
|
+
if (!publicDir) throw new Error("Nitro public output directory is required to build the sitemap.");
|
|
195
|
+
return publicDir;
|
|
196
|
+
}
|
|
197
|
+
function readDirectoryEntries(path) {
|
|
198
|
+
try {
|
|
199
|
+
return readdirSync(path).sort();
|
|
200
|
+
} catch (error) {
|
|
201
|
+
return [`<<unable to read directory: ${error instanceof Error ? error.message : String(error)}>>`];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function getPathDebugInfo(path) {
|
|
205
|
+
return {
|
|
206
|
+
rawPath: path,
|
|
207
|
+
normalizedPath: normalizePath(path),
|
|
208
|
+
exists: existsSync(path),
|
|
209
|
+
entries: existsSync(path) ? readDirectoryEntries(path) : []
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function assetSourceToString(source) {
|
|
213
|
+
return typeof source === "string" ? source : Buffer.from(source).toString("utf8");
|
|
214
|
+
}
|
|
215
|
+
function captureClientIndexHtmlFromBundle(bundle, hook) {
|
|
216
|
+
const indexHtmlAsset = Object.values(bundle).find((chunk) => chunk.type === "asset" && chunk.fileName === "index.html" && typeof chunk.source !== "undefined");
|
|
217
|
+
if (!indexHtmlAsset?.source) {
|
|
218
|
+
debugNitro(`client bundle did not expose index.html during ${hook}`, {
|
|
219
|
+
hook,
|
|
220
|
+
bundleKeys: Object.keys(bundle).sort(),
|
|
221
|
+
assetFileNames: Object.values(bundle).filter((chunk) => chunk.type === "asset").map((chunk) => chunk.fileName).filter(Boolean)
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const indexHtml = assetSourceToString(indexHtmlAsset.source);
|
|
226
|
+
debugNitro(`captured client bundle index.html asset during ${hook}`, {
|
|
227
|
+
hook,
|
|
228
|
+
fileName: indexHtmlAsset.fileName,
|
|
229
|
+
htmlLength: indexHtml.length
|
|
230
|
+
});
|
|
231
|
+
return indexHtml;
|
|
148
232
|
}
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
233
|
+
function registerIndexHtmlVirtual(nitroConfig, clientOutputPath, inlineIndexHtml) {
|
|
234
|
+
const indexHtmlPath = resolve(clientOutputPath, "index.html");
|
|
235
|
+
debugNitro("registerIndexHtmlVirtual inspecting client output", {
|
|
236
|
+
platform: process.platform,
|
|
237
|
+
cwd: process.cwd(),
|
|
238
|
+
clientOutputPath,
|
|
239
|
+
clientOutputPathInfo: getPathDebugInfo(clientOutputPath),
|
|
240
|
+
indexHtmlPath,
|
|
241
|
+
indexHtmlExists: existsSync(indexHtmlPath),
|
|
242
|
+
hasInlineIndexHtml: typeof inlineIndexHtml === "string"
|
|
243
|
+
});
|
|
244
|
+
if (!existsSync(indexHtmlPath) && typeof inlineIndexHtml !== "string") {
|
|
245
|
+
debugNitro("registerIndexHtmlVirtual missing index.html", {
|
|
246
|
+
platform: process.platform,
|
|
247
|
+
cwd: process.cwd(),
|
|
248
|
+
clientOutputPath,
|
|
249
|
+
clientOutputPathInfo: getPathDebugInfo(clientOutputPath),
|
|
250
|
+
indexHtmlPath,
|
|
251
|
+
hasInlineIndexHtml: typeof inlineIndexHtml === "string",
|
|
252
|
+
nitroOutput: nitroConfig.output,
|
|
253
|
+
nitroPublicAssets: nitroConfig.publicAssets
|
|
254
|
+
});
|
|
255
|
+
throw new Error(`[analog] Client build output not found at ${indexHtmlPath}.\nEnsure the client environment build completed successfully before the server build.`);
|
|
256
|
+
}
|
|
257
|
+
const indexHtml = typeof inlineIndexHtml === "string" ? inlineIndexHtml : readFileSync(indexHtmlPath, "utf8");
|
|
258
|
+
debugNitro("registerIndexHtmlVirtual using HTML template source", {
|
|
259
|
+
source: typeof inlineIndexHtml === "string" ? "captured client bundle asset" : "client output index.html file",
|
|
260
|
+
indexHtmlPath
|
|
261
|
+
});
|
|
262
|
+
nitroConfig.virtual = {
|
|
263
|
+
...nitroConfig.virtual,
|
|
264
|
+
"#analog/index": `export default ${JSON.stringify(indexHtml)};`
|
|
265
|
+
};
|
|
159
266
|
}
|
|
160
267
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
268
|
+
* Converts the built SSR entry path into a specifier that Nitro's bundler
|
|
269
|
+
* can resolve, including all relative `./assets/*` chunk imports inside
|
|
270
|
+
* the entry.
|
|
271
|
+
*
|
|
272
|
+
* The returned path **must** be an absolute filesystem path with forward
|
|
273
|
+
* slashes (e.g. `D:/a/analog/dist/apps/blog-app/ssr/main.server.js`).
|
|
274
|
+
* This lets Rollup/Rolldown determine the entry's directory and resolve
|
|
275
|
+
* sibling chunk imports like `./assets/core-DTazUigR.js` correctly.
|
|
276
|
+
*
|
|
277
|
+
* ## Why not pathToFileURL() on Windows?
|
|
278
|
+
*
|
|
279
|
+
* Earlier versions converted the path to a `file:///D:/a/...` URL on
|
|
280
|
+
* Windows, which worked with Nitro v2 + Rollup. Nitro v3 switched its
|
|
281
|
+
* default bundler to Rolldown, and Rolldown does **not** extract the
|
|
282
|
+
* importer directory from `file://` URLs. This caused every relative
|
|
283
|
+
* import inside the SSR entry to fail during the prerender build:
|
|
284
|
+
*
|
|
285
|
+
* [RESOLVE_ERROR] Could not resolve './assets/core-DTazUigR.js'
|
|
286
|
+
* in ../../dist/apps/blog-app/ssr/main.server.js
|
|
287
|
+
*
|
|
288
|
+
* `normalizePath()` (from Vite) simply converts backslashes to forward
|
|
289
|
+
* slashes, which both Rollup and Rolldown handle correctly on all
|
|
290
|
+
* platforms.
|
|
291
|
+
*/
|
|
185
292
|
function toNitroSsrEntrypointSpecifier(ssrEntryPath) {
|
|
186
|
-
|
|
293
|
+
return normalizePath(ssrEntryPath);
|
|
187
294
|
}
|
|
188
295
|
function applySsrEntryAlias(nitroConfig, options, workspaceRoot, rootDir) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
296
|
+
const ssrOutDir = options?.ssrBuildDir || resolve(workspaceRoot, "dist", rootDir, "ssr");
|
|
297
|
+
if (options?.ssr || nitroConfig.prerender?.routes?.length) {
|
|
298
|
+
const ssrEntry = toNitroSsrEntrypointSpecifier(resolveBuiltSsrEntryPath(ssrOutDir));
|
|
299
|
+
nitroConfig.alias = {
|
|
300
|
+
...nitroConfig.alias,
|
|
301
|
+
"#analog/ssr": ssrEntry
|
|
302
|
+
};
|
|
303
|
+
}
|
|
198
304
|
}
|
|
199
305
|
function resolveBuiltSsrEntryPath(ssrOutDir) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
return ssrEntryPath;
|
|
306
|
+
const candidatePaths = [
|
|
307
|
+
resolve(ssrOutDir, "main.server.mjs"),
|
|
308
|
+
resolve(ssrOutDir, "main.server.js"),
|
|
309
|
+
resolve(ssrOutDir, "main.server")
|
|
310
|
+
];
|
|
311
|
+
const ssrEntryPath = candidatePaths.find((candidatePath) => existsSync(candidatePath));
|
|
312
|
+
if (!ssrEntryPath) throw new Error(`Unable to locate the built SSR entry in "${ssrOutDir}". Expected one of: ${candidatePaths.join(", ")}`);
|
|
313
|
+
return ssrEntryPath;
|
|
210
314
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
315
|
+
function nitro(options, nitroOptions) {
|
|
316
|
+
const workspaceRoot = options?.workspaceRoot ?? process.cwd();
|
|
317
|
+
const sourceRoot = options?.sourceRoot ?? "src";
|
|
318
|
+
let isTest = process.env.NODE_ENV === "test" || !!process.env["VITEST"];
|
|
319
|
+
const baseURL = process.env["NITRO_APP_BASE_URL"] || "";
|
|
320
|
+
const prefix = baseURL ? baseURL.substring(0, baseURL.length - 1) : "";
|
|
321
|
+
const apiPrefix = `/${options?.apiPrefix || "api"}`;
|
|
322
|
+
const useAPIMiddleware = typeof options?.useAPIMiddleware !== "undefined" ? options?.useAPIMiddleware : true;
|
|
323
|
+
const viteRolldownOutput = options?.vite?.build?.rolldownOptions?.output;
|
|
324
|
+
const viteRolldownOutputConfig = viteRolldownOutput && !Array.isArray(viteRolldownOutput) ? viteRolldownOutput : void 0;
|
|
325
|
+
const codeSplitting = viteRolldownOutputConfig?.codeSplitting;
|
|
326
|
+
let isBuild = false;
|
|
327
|
+
let isServe = false;
|
|
328
|
+
let ssrBuild = false;
|
|
329
|
+
let config;
|
|
330
|
+
let nitroConfig;
|
|
331
|
+
let environmentBuild = false;
|
|
332
|
+
let hasAPIDir = false;
|
|
333
|
+
let clientOutputPath = "";
|
|
334
|
+
let clientIndexHtml;
|
|
335
|
+
let legacyClientSubBuild = false;
|
|
336
|
+
const rollupExternalEntries = [];
|
|
337
|
+
const sitemapRoutes = [];
|
|
338
|
+
const routeSitemaps = {};
|
|
339
|
+
const routeSourceFiles = {};
|
|
340
|
+
let rootDir = workspaceRoot;
|
|
341
|
+
return [
|
|
342
|
+
options?.ssr ? devServerPlugin({
|
|
343
|
+
entryServer: options?.entryServer,
|
|
344
|
+
index: options?.index,
|
|
345
|
+
routeRules: nitroOptions?.routeRules,
|
|
346
|
+
i18n: options?.i18n
|
|
347
|
+
}) : false,
|
|
348
|
+
{
|
|
349
|
+
name: "@analogjs/vite-plugin-nitro",
|
|
350
|
+
async config(userConfig, { mode, command }) {
|
|
351
|
+
isServe = command === "serve";
|
|
352
|
+
isBuild = command === "build";
|
|
353
|
+
ssrBuild = userConfig.build?.ssr === true;
|
|
354
|
+
config = cloneUserConfig(userConfig);
|
|
355
|
+
isTest = isTest ? isTest : mode === "test";
|
|
356
|
+
rollupExternalEntries.length = 0;
|
|
357
|
+
clientIndexHtml = void 0;
|
|
358
|
+
sitemapRoutes.length = 0;
|
|
359
|
+
for (const key of Object.keys(routeSitemaps)) delete routeSitemaps[key];
|
|
360
|
+
for (const key of Object.keys(routeSourceFiles)) delete routeSourceFiles[key];
|
|
361
|
+
const resolvedConfigRoot = config.root ? resolve(workspaceRoot, config.root) : workspaceRoot;
|
|
362
|
+
rootDir = relative(workspaceRoot, resolvedConfigRoot) || ".";
|
|
363
|
+
hasAPIDir = existsSync(resolve(workspaceRoot, rootDir, `${sourceRoot}/server/routes/${options?.apiPrefix || "api"}`));
|
|
364
|
+
const buildPreset = process.env["BUILD_PRESET"] ?? nitroOptions?.preset ?? (process.env["VERCEL"] ? "vercel" : void 0);
|
|
365
|
+
const pageHandlers = getPageHandlers({
|
|
366
|
+
workspaceRoot,
|
|
367
|
+
sourceRoot,
|
|
368
|
+
rootDir,
|
|
369
|
+
additionalPagesDirs: options?.additionalPagesDirs,
|
|
370
|
+
hasAPIDir
|
|
371
|
+
});
|
|
372
|
+
const resolvedClientOutputPath = resolveClientOutputPath(clientOutputPath, workspaceRoot, rootDir, config.build?.outDir);
|
|
373
|
+
debugNitro("nitro config resolved client output path", {
|
|
374
|
+
platform: process.platform,
|
|
375
|
+
workspaceRoot,
|
|
376
|
+
configRoot: config.root,
|
|
377
|
+
resolvedConfigRoot,
|
|
378
|
+
rootDir,
|
|
379
|
+
buildOutDir: config.build?.outDir,
|
|
380
|
+
clientOutputPath,
|
|
381
|
+
resolvedClientOutputPath,
|
|
382
|
+
hasEnvironmentConfig: !!config.environments,
|
|
383
|
+
clientEnvironmentOutDir: config.environments?.["client"] && typeof config.environments["client"] === "object" && "build" in config.environments["client"] ? config.environments["client"].build?.outDir : void 0
|
|
384
|
+
});
|
|
385
|
+
nitroConfig = {
|
|
386
|
+
rootDir: normalizePath(rootDir),
|
|
387
|
+
preset: buildPreset,
|
|
388
|
+
compatibilityDate: "2025-11-19",
|
|
389
|
+
logLevel: nitroOptions?.logLevel || 0,
|
|
390
|
+
serverDir: normalizePath(`${sourceRoot}/server`),
|
|
391
|
+
scanDirs: [normalizePath(`${rootDir}/${sourceRoot}/server`), ...(options?.additionalAPIDirs || []).map((dir) => normalizePath(`${workspaceRoot}${dir}`))],
|
|
392
|
+
output: {
|
|
393
|
+
dir: normalizePath(resolve(workspaceRoot, "dist", rootDir, "analog")),
|
|
394
|
+
publicDir: normalizePath(resolve(workspaceRoot, "dist", rootDir, "analog/public"))
|
|
395
|
+
},
|
|
396
|
+
buildDir: normalizePath(resolve(workspaceRoot, "dist", rootDir, ".nitro")),
|
|
397
|
+
typescript: { generateTsConfig: false },
|
|
398
|
+
runtimeConfig: {
|
|
399
|
+
apiPrefix: apiPrefix.substring(1),
|
|
400
|
+
prefix
|
|
401
|
+
},
|
|
402
|
+
renderer: false,
|
|
403
|
+
imports: { autoImport: false },
|
|
404
|
+
hooks: { "rollup:before": createRollupBeforeHook(rollupExternalEntries) },
|
|
405
|
+
rollupConfig: {
|
|
406
|
+
onwarn(warning) {
|
|
407
|
+
if (warning.message.includes("empty chunk") && warning.message.endsWith(".server")) return;
|
|
408
|
+
},
|
|
409
|
+
plugins: [pageEndpointsPlugin()]
|
|
410
|
+
},
|
|
411
|
+
handlers: [...hasAPIDir ? [] : useAPIMiddleware ? [createNitroMiddlewareHandler("#ANALOG_API_MIDDLEWARE")] : [], ...pageHandlers],
|
|
412
|
+
routeRules: hasAPIDir ? void 0 : useAPIMiddleware ? void 0 : { [`${prefix}${apiPrefix}/**`]: { proxy: { to: "/**" } } },
|
|
413
|
+
virtual: {
|
|
414
|
+
"#ANALOG_SSR_RENDERER": ssrRenderer(),
|
|
415
|
+
"#ANALOG_CLIENT_RENDERER": clientRenderer(),
|
|
416
|
+
...hasAPIDir ? {} : { "#ANALOG_API_MIDDLEWARE": apiMiddleware }
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
if (isVercelPreset(buildPreset)) nitroConfig = withVercelOutputAPI(nitroConfig, workspaceRoot);
|
|
420
|
+
if (isCloudflarePreset(buildPreset)) nitroConfig = withCloudflareOutput(nitroConfig);
|
|
421
|
+
if (isNetlifyPreset(buildPreset) && rootDir === "." && !existsSync(resolve(workspaceRoot, "netlify.toml"))) nitroConfig = withNetlifyOutputAPI(nitroConfig, workspaceRoot);
|
|
422
|
+
if (isFirebaseAppHosting()) nitroConfig = withAppHostingOutput(nitroConfig);
|
|
423
|
+
if (!ssrBuild && !isTest) {
|
|
424
|
+
clientOutputPath = resolvedClientOutputPath;
|
|
425
|
+
debugNitro("nitro config cached client output path for later SSR/Nitro build", {
|
|
426
|
+
ssrBuild,
|
|
427
|
+
isTest,
|
|
428
|
+
clientOutputPath
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
nitroConfig.alias = {};
|
|
432
|
+
if (isBuild) {
|
|
433
|
+
nitroConfig.publicAssets = [{
|
|
434
|
+
dir: normalizePath(resolvedClientOutputPath),
|
|
435
|
+
maxAge: 0
|
|
436
|
+
}];
|
|
437
|
+
const rendererHandler = options?.ssr ? "#ANALOG_SSR_RENDERER" : "#ANALOG_CLIENT_RENDERER";
|
|
438
|
+
nitroConfig.handlers = [...nitroConfig.handlers || [], {
|
|
439
|
+
handler: rendererHandler,
|
|
440
|
+
route: "/**",
|
|
441
|
+
lazy: true
|
|
442
|
+
}];
|
|
443
|
+
if (isEmptyPrerenderRoutes(options)) {
|
|
444
|
+
nitroConfig.prerender = {};
|
|
445
|
+
nitroConfig.prerender.routes = ["/"];
|
|
446
|
+
}
|
|
447
|
+
if (options?.prerender) {
|
|
448
|
+
nitroConfig.prerender = nitroConfig.prerender ?? {};
|
|
449
|
+
nitroConfig.prerender.crawlLinks = options?.prerender?.discover;
|
|
450
|
+
let routes = [];
|
|
451
|
+
const prerenderRoutes = options?.prerender?.routes;
|
|
452
|
+
const hasExplicitPrerenderRoutes = typeof prerenderRoutes === "function" || Array.isArray(prerenderRoutes);
|
|
453
|
+
if (isArrayWithElements(prerenderRoutes)) routes = prerenderRoutes;
|
|
454
|
+
else if (typeof prerenderRoutes === "function") routes = await prerenderRoutes();
|
|
455
|
+
const resolvedPrerenderRoutes = routes.reduce((prev, current) => {
|
|
456
|
+
if (!current) return prev;
|
|
457
|
+
if (typeof current === "string") {
|
|
458
|
+
prev.push(current);
|
|
459
|
+
sitemapRoutes.push(current);
|
|
460
|
+
return prev;
|
|
461
|
+
}
|
|
462
|
+
if ("route" in current) {
|
|
463
|
+
if (current.sitemap) routeSitemaps[current.route] = current.sitemap;
|
|
464
|
+
if (current.outputSourceFile) {
|
|
465
|
+
const sourcePath = resolve(workspaceRoot, rootDir, current.outputSourceFile);
|
|
466
|
+
routeSourceFiles[current.route] = readFileSync(sourcePath, "utf8");
|
|
467
|
+
}
|
|
468
|
+
prev.push(current.route);
|
|
469
|
+
sitemapRoutes.push(current.route);
|
|
470
|
+
if ("staticData" in current) prev.push(`${apiPrefix}/_analog/pages/${current.route}`);
|
|
471
|
+
return prev;
|
|
472
|
+
}
|
|
473
|
+
getMatchingContentFilesWithFrontMatter(workspaceRoot, rootDir, current.contentDir).forEach((f) => {
|
|
474
|
+
const result = current.transform(f);
|
|
475
|
+
if (result) {
|
|
476
|
+
if (current.sitemap) routeSitemaps[result] = current.sitemap && typeof current.sitemap === "function" ? current.sitemap?.(f) : current.sitemap;
|
|
477
|
+
if (current.outputSourceFile) {
|
|
478
|
+
const sourceContent = current.outputSourceFile(f);
|
|
479
|
+
if (sourceContent) routeSourceFiles[result] = sourceContent;
|
|
480
|
+
}
|
|
481
|
+
prev.push(result);
|
|
482
|
+
sitemapRoutes.push(result);
|
|
483
|
+
if ("staticData" in current) prev.push(`${apiPrefix}/_analog/pages/${result}`);
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return prev;
|
|
487
|
+
}, []);
|
|
488
|
+
nitroConfig.prerender.routes = hasExplicitPrerenderRoutes || resolvedPrerenderRoutes.length ? resolvedPrerenderRoutes : nitroConfig.prerender.routes ?? [];
|
|
489
|
+
}
|
|
490
|
+
if (ssrBuild || options?.ssr || nitroConfig.prerender?.routes?.length) {
|
|
491
|
+
nitroConfig.noExternals = appendNoExternals(nitroConfig.noExternals, "es-toolkit");
|
|
492
|
+
if (process.platform === "win32") nitroConfig.noExternals = appendNoExternals(nitroConfig.noExternals, "std-env");
|
|
493
|
+
rollupExternalEntries.push("rxjs", "node-fetch-native/dist/polyfill", "sharp");
|
|
494
|
+
nitroConfig = {
|
|
495
|
+
...nitroConfig,
|
|
496
|
+
handlers: [
|
|
497
|
+
...hasAPIDir ? [] : useAPIMiddleware ? [createNitroMiddlewareHandler("#ANALOG_API_MIDDLEWARE")] : [],
|
|
498
|
+
...pageHandlers,
|
|
499
|
+
{
|
|
500
|
+
handler: rendererHandler,
|
|
501
|
+
route: "/**",
|
|
502
|
+
lazy: true
|
|
503
|
+
}
|
|
504
|
+
]
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
nitroConfig = mergeConfig(nitroConfig, nitroOptions);
|
|
509
|
+
if (environmentBuild || ssrBuild || isServe) return {};
|
|
510
|
+
return {
|
|
511
|
+
environments: {
|
|
512
|
+
client: { build: {
|
|
513
|
+
outDir: config?.build?.outDir || resolve(workspaceRoot, "dist", rootDir, "client"),
|
|
514
|
+
emptyOutDir: true,
|
|
515
|
+
...isRolldown() && codeSplitting !== void 0 ? { rolldownOptions: { output: {
|
|
516
|
+
...viteRolldownOutputConfig,
|
|
517
|
+
codeSplitting
|
|
518
|
+
} } } : {}
|
|
519
|
+
} },
|
|
520
|
+
ssr: { build: {
|
|
521
|
+
ssr: true,
|
|
522
|
+
[getBundleOptionsKey()]: { input: options?.entryServer || resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`) },
|
|
523
|
+
outDir: options?.ssrBuildDir || resolve(workspaceRoot, "dist", rootDir, "ssr"),
|
|
524
|
+
emptyOutDir: false
|
|
525
|
+
} }
|
|
526
|
+
},
|
|
527
|
+
builder: {
|
|
528
|
+
sharedPlugins: true,
|
|
529
|
+
buildApp: async (builder) => {
|
|
530
|
+
environmentBuild = true;
|
|
531
|
+
debugNitro("builder.buildApp starting", {
|
|
532
|
+
platform: process.platform,
|
|
533
|
+
workspaceRoot,
|
|
534
|
+
rootDir,
|
|
535
|
+
cachedClientOutputPath: clientOutputPath,
|
|
536
|
+
configuredBuildOutDir: config.build?.outDir,
|
|
537
|
+
clientEnvironmentOutDir: getEnvironmentBuildOutDir(builder.environments["client"]),
|
|
538
|
+
ssrEnvironmentOutDir: getEnvironmentBuildOutDir(builder.environments["ssr"])
|
|
539
|
+
});
|
|
540
|
+
await builder.build(builder.environments["client"]);
|
|
541
|
+
const postClientBuildOutputPath = resolveBuiltClientOutputPath(clientOutputPath, workspaceRoot, rootDir, config.build?.outDir, builder.environments["client"]);
|
|
542
|
+
registerIndexHtmlVirtual(nitroConfig, postClientBuildOutputPath, clientIndexHtml);
|
|
543
|
+
debugNitro("builder.buildApp completed client build", {
|
|
544
|
+
postClientBuildOutputPath,
|
|
545
|
+
postClientBuildOutputInfo: getPathDebugInfo(postClientBuildOutputPath),
|
|
546
|
+
postClientBuildIndexHtmlPath: resolve(postClientBuildOutputPath, "index.html"),
|
|
547
|
+
postClientBuildIndexHtmlExists: existsSync(resolve(postClientBuildOutputPath, "index.html"))
|
|
548
|
+
});
|
|
549
|
+
if (options?.ssr || nitroConfig.prerender?.routes?.length) {
|
|
550
|
+
debugSsr("builder.buildApp starting SSR build", {
|
|
551
|
+
ssrEnabled: options?.ssr,
|
|
552
|
+
prerenderRoutes: nitroConfig.prerender?.routes
|
|
553
|
+
});
|
|
554
|
+
/**
|
|
555
|
+
* This launches the SSR environment as a second build from the
|
|
556
|
+
* shared plugin graph above. When debugging an apparent
|
|
557
|
+
* duplicate `@analogjs/vite-plugin-angular` registration, this
|
|
558
|
+
* is the handoff to inspect: the SSR builder replays the shared
|
|
559
|
+
* plugins for the server pass and may therefore expose multiple
|
|
560
|
+
* Angular-plugin entries in the SSR resolved config.
|
|
561
|
+
*
|
|
562
|
+
* That is expected for this orchestration path and should not
|
|
563
|
+
* be treated the same as a duplicated client build, where two
|
|
564
|
+
* Angular plugin instances would maintain separate style maps.
|
|
565
|
+
*/
|
|
566
|
+
await builder.build(builder.environments["ssr"]);
|
|
567
|
+
debugSsr("builder.buildApp completed SSR build", { ssrOutputPath: options?.ssrBuildDir || resolve(workspaceRoot, "dist", rootDir, "ssr") });
|
|
568
|
+
}
|
|
569
|
+
applySsrEntryAlias(nitroConfig, options, workspaceRoot, rootDir);
|
|
570
|
+
const resolvedClientOutputPath = resolveBuiltClientOutputPath(clientOutputPath, workspaceRoot, rootDir, config.build?.outDir, builder.environments["client"]);
|
|
571
|
+
nitroConfig.publicAssets = [{
|
|
572
|
+
dir: normalizePath(resolvedClientOutputPath),
|
|
573
|
+
maxAge: 0
|
|
574
|
+
}];
|
|
575
|
+
debugNitro("builder.buildApp resolved final client output path before Nitro build", {
|
|
576
|
+
resolvedClientOutputPath,
|
|
577
|
+
resolvedClientOutputInfo: getPathDebugInfo(resolvedClientOutputPath),
|
|
578
|
+
nitroPublicAssets: nitroConfig.publicAssets
|
|
579
|
+
});
|
|
580
|
+
await buildServer(options, nitroConfig, routeSourceFiles);
|
|
581
|
+
if (nitroConfig.prerender?.routes?.length && options?.prerender?.sitemap) {
|
|
582
|
+
console.log("Building Sitemap...");
|
|
583
|
+
await buildSitemap(config, options.prerender.sitemap, sitemapRoutes.length ? sitemapRoutes : nitroConfig.prerender.routes, getNitroPublicOutputDir(nitroConfig), routeSitemaps, { apiPrefix: options?.apiPrefix || "api" });
|
|
584
|
+
}
|
|
585
|
+
console.log(`\n\nThe '@analogjs/platform' server has been successfully built.`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
generateBundle(_options, bundle) {
|
|
591
|
+
if (!isBuild || ssrBuild) return;
|
|
592
|
+
clientIndexHtml = captureClientIndexHtmlFromBundle(bundle, "generateBundle") ?? clientIndexHtml;
|
|
593
|
+
},
|
|
594
|
+
writeBundle(_options, bundle) {
|
|
595
|
+
if (!isBuild || ssrBuild) return;
|
|
596
|
+
clientIndexHtml = captureClientIndexHtmlFromBundle(bundle, "writeBundle") ?? clientIndexHtml;
|
|
597
|
+
},
|
|
598
|
+
async configureServer(viteServer) {
|
|
599
|
+
if (isServe && !isTest) {
|
|
600
|
+
const nitro = await createNitro({
|
|
601
|
+
dev: true,
|
|
602
|
+
builder: "rollup",
|
|
603
|
+
...nitroConfig
|
|
604
|
+
});
|
|
605
|
+
const server = createDevServer(nitro);
|
|
606
|
+
await build(nitro);
|
|
607
|
+
const nitroSourceRoots = [normalizePath(resolve(workspaceRoot, rootDir, `${sourceRoot}/server`)), ...(options?.additionalAPIDirs || []).map((dir) => normalizePath(`${workspaceRoot}${dir}`))];
|
|
608
|
+
const isNitroSourceFile = (path) => {
|
|
609
|
+
const normalizedPath = normalizePath(path);
|
|
610
|
+
return nitroSourceRoots.some((root) => normalizedPath === root || normalizedPath.startsWith(`${root}/`));
|
|
611
|
+
};
|
|
612
|
+
let nitroRebuildPromise;
|
|
613
|
+
let nitroRebuildPending = false;
|
|
614
|
+
const rebuildNitroServer = () => {
|
|
615
|
+
if (nitroRebuildPromise) {
|
|
616
|
+
nitroRebuildPending = true;
|
|
617
|
+
return nitroRebuildPromise;
|
|
618
|
+
}
|
|
619
|
+
nitroRebuildPromise = (async () => {
|
|
620
|
+
do {
|
|
621
|
+
nitroRebuildPending = false;
|
|
622
|
+
await build(nitro);
|
|
623
|
+
} while (nitroRebuildPending);
|
|
624
|
+
viteServer.ws.send("analog:debug-full-reload", {
|
|
625
|
+
plugin: "vite-plugin-nitro",
|
|
626
|
+
reason: "nitro-server-rebuilt"
|
|
627
|
+
});
|
|
628
|
+
viteServer.ws.send({ type: "full-reload" });
|
|
629
|
+
})().catch((error) => {
|
|
630
|
+
viteServer.config.logger.error(`[analog] Failed to rebuild Nitro dev server.\n${error instanceof Error ? error.stack || error.message : String(error)}`);
|
|
631
|
+
}).finally(() => {
|
|
632
|
+
nitroRebuildPromise = void 0;
|
|
633
|
+
});
|
|
634
|
+
return nitroRebuildPromise;
|
|
635
|
+
};
|
|
636
|
+
const onNitroSourceChange = (path) => {
|
|
637
|
+
if (!isNitroSourceFile(path)) return;
|
|
638
|
+
rebuildNitroServer();
|
|
639
|
+
};
|
|
640
|
+
viteServer.watcher.on("add", onNitroSourceChange);
|
|
641
|
+
viteServer.watcher.on("change", onNitroSourceChange);
|
|
642
|
+
viteServer.watcher.on("unlink", onNitroSourceChange);
|
|
643
|
+
const apiHandler = async (req, res) => {
|
|
644
|
+
await writeWebResponseToNode(res, await server.fetch(toWebRequest(req)));
|
|
645
|
+
};
|
|
646
|
+
if (hasAPIDir) viteServer.middlewares.use((req, res, next) => {
|
|
647
|
+
if (req.url?.startsWith(`${prefix}${apiPrefix}`)) {
|
|
648
|
+
apiHandler(req, res).catch((error) => next(error));
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
next();
|
|
652
|
+
});
|
|
653
|
+
else viteServer.middlewares.use(apiPrefix, (req, res, next) => {
|
|
654
|
+
apiHandler(req, res).catch((error) => next(error));
|
|
655
|
+
});
|
|
656
|
+
viteServer.httpServer?.once("listening", () => {
|
|
657
|
+
process.env["ANALOG_HOST"] = !viteServer.config.server.host ? "localhost" : viteServer.config.server.host;
|
|
658
|
+
process.env["ANALOG_PORT"] = `${viteServer.config.server.port}`;
|
|
659
|
+
});
|
|
660
|
+
if (nitroOptions?.experimental?.websocket) {
|
|
661
|
+
debugNitro("experimental websocket upgrade handler enabled");
|
|
662
|
+
viteServer.httpServer?.on("upgrade", server.upgrade);
|
|
663
|
+
}
|
|
664
|
+
console.log(`\n\nThe server endpoints are accessible under the "${prefix}${apiPrefix}" path.`);
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
async closeBundle() {
|
|
668
|
+
if (legacyClientSubBuild) return;
|
|
669
|
+
if (environmentBuild) return;
|
|
670
|
+
if (ssrBuild) return;
|
|
671
|
+
if (isBuild) {
|
|
672
|
+
const resolvedClientOutputPath = resolveClientOutputPath(clientOutputPath, workspaceRoot, rootDir, config.build?.outDir);
|
|
673
|
+
debugNitro("closeBundle resolved client output path before legacy SSR build", {
|
|
674
|
+
platform: process.platform,
|
|
675
|
+
workspaceRoot,
|
|
676
|
+
rootDir,
|
|
677
|
+
cachedClientOutputPath: clientOutputPath,
|
|
678
|
+
configuredBuildOutDir: config.build?.outDir,
|
|
679
|
+
resolvedClientOutputPath,
|
|
680
|
+
resolvedClientOutputInfo: getPathDebugInfo(resolvedClientOutputPath)
|
|
681
|
+
});
|
|
682
|
+
const indexHtmlPath = resolve(resolvedClientOutputPath, "index.html");
|
|
683
|
+
if (!existsSync(indexHtmlPath) && typeof clientIndexHtml !== "string") {
|
|
684
|
+
debugNitro("closeBundle rebuilding missing client output before SSR/Nitro", {
|
|
685
|
+
platform: process.platform,
|
|
686
|
+
workspaceRoot,
|
|
687
|
+
rootDir,
|
|
688
|
+
configuredBuildOutDir: config.build?.outDir,
|
|
689
|
+
resolvedClientOutputPath,
|
|
690
|
+
indexHtmlPath
|
|
691
|
+
});
|
|
692
|
+
legacyClientSubBuild = true;
|
|
693
|
+
try {
|
|
694
|
+
await buildClientApp(config, options);
|
|
695
|
+
} finally {
|
|
696
|
+
legacyClientSubBuild = false;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
registerIndexHtmlVirtual(nitroConfig, resolvedClientOutputPath, clientIndexHtml);
|
|
700
|
+
if (options?.ssr) {
|
|
701
|
+
console.log("Building SSR application...");
|
|
702
|
+
await buildSSRApp(config, options);
|
|
703
|
+
debugSsr("closeBundle completed standalone SSR build", {
|
|
704
|
+
ssrBuildDir: options?.ssrBuildDir || resolve(workspaceRoot, "dist", rootDir, "ssr"),
|
|
705
|
+
clientOutputPathInfo: clientOutputPath ? getPathDebugInfo(clientOutputPath) : null
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
applySsrEntryAlias(nitroConfig, options, workspaceRoot, rootDir);
|
|
709
|
+
debugNitro("closeBundle resolved client output path before Nitro build", {
|
|
710
|
+
platform: process.platform,
|
|
711
|
+
workspaceRoot,
|
|
712
|
+
rootDir,
|
|
713
|
+
cachedClientOutputPath: clientOutputPath,
|
|
714
|
+
configuredBuildOutDir: config.build?.outDir,
|
|
715
|
+
resolvedClientOutputPath,
|
|
716
|
+
resolvedClientOutputInfo: getPathDebugInfo(resolvedClientOutputPath)
|
|
717
|
+
});
|
|
718
|
+
registerIndexHtmlVirtual(nitroConfig, resolvedClientOutputPath, clientIndexHtml);
|
|
719
|
+
await buildServer(options, nitroConfig, routeSourceFiles);
|
|
720
|
+
if (nitroConfig.prerender?.routes?.length && options?.prerender?.sitemap) {
|
|
721
|
+
console.log("Building Sitemap...");
|
|
722
|
+
await buildSitemap(config, options.prerender.sitemap, sitemapRoutes.length ? sitemapRoutes : nitroConfig.prerender.routes, getNitroPublicOutputDir(nitroConfig), routeSitemaps, { apiPrefix: options?.apiPrefix || "api" });
|
|
723
|
+
}
|
|
724
|
+
console.log(`\n\nThe '@analogjs/platform' server has been successfully built.`);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
name: "@analogjs/vite-plugin-nitro-api-prefix",
|
|
730
|
+
config() {
|
|
731
|
+
return { define: {
|
|
732
|
+
ANALOG_API_PREFIX: `"${baseURL.substring(1)}${apiPrefix.substring(1)}"`,
|
|
733
|
+
...options?.i18n ? {
|
|
734
|
+
ANALOG_I18N_DEFAULT_LOCALE: JSON.stringify(options.i18n.defaultLocale),
|
|
735
|
+
ANALOG_I18N_LOCALES: JSON.stringify(options.i18n.locales)
|
|
736
|
+
} : {}
|
|
737
|
+
} };
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
];
|
|
618
741
|
}
|
|
619
742
|
function isEmptyPrerenderRoutes(options) {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
return !options.prerender?.routes;
|
|
743
|
+
if (!options || isArrayWithElements(options?.prerender?.routes)) return false;
|
|
744
|
+
return !options.prerender?.routes;
|
|
624
745
|
}
|
|
625
746
|
function isArrayWithElements(arr) {
|
|
626
|
-
|
|
747
|
+
return !!(Array.isArray(arr) && arr.length);
|
|
627
748
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
...nitroConfig?.output,
|
|
645
|
-
dir: normalizePath(resolve(workspaceRoot, '.vercel', 'output')),
|
|
646
|
-
publicDir: normalizePath(resolve(workspaceRoot, '.vercel', 'output/static')),
|
|
647
|
-
},
|
|
749
|
+
var withVercelOutputAPI = (nitroConfig, workspaceRoot) => ({
|
|
750
|
+
...nitroConfig,
|
|
751
|
+
preset: nitroConfig?.preset ?? "vercel",
|
|
752
|
+
vercel: {
|
|
753
|
+
...nitroConfig?.vercel,
|
|
754
|
+
entryFormat: nitroConfig?.vercel?.entryFormat ?? "node",
|
|
755
|
+
functions: {
|
|
756
|
+
runtime: nitroConfig?.vercel?.functions?.runtime ?? "nodejs24.x",
|
|
757
|
+
...nitroConfig?.vercel?.functions
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
output: {
|
|
761
|
+
...nitroConfig?.output,
|
|
762
|
+
dir: normalizePath(resolve(workspaceRoot, ".vercel", "output")),
|
|
763
|
+
publicDir: normalizePath(resolve(workspaceRoot, ".vercel", "output/static"))
|
|
764
|
+
}
|
|
648
765
|
});
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
...nitroConfig,
|
|
657
|
-
output: {
|
|
658
|
-
...nitroConfig?.output,
|
|
659
|
-
serverDir: '{{ output.publicDir }}/_worker.js',
|
|
660
|
-
},
|
|
766
|
+
var isCloudflarePreset = (buildPreset) => process.env["CF_PAGES"] || buildPreset && (buildPreset.toLowerCase().includes("cloudflare-pages") || buildPreset.toLowerCase().includes("cloudflare_pages"));
|
|
767
|
+
var withCloudflareOutput = (nitroConfig) => ({
|
|
768
|
+
...nitroConfig,
|
|
769
|
+
output: {
|
|
770
|
+
...nitroConfig?.output,
|
|
771
|
+
serverDir: "{{ output.publicDir }}/_worker.js"
|
|
772
|
+
}
|
|
661
773
|
});
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
};
|
|
774
|
+
var isFirebaseAppHosting = () => !!process.env["NG_BUILD_LOGS_JSON"];
|
|
775
|
+
var withAppHostingOutput = (nitroConfig) => {
|
|
776
|
+
let hasOutput = false;
|
|
777
|
+
return {
|
|
778
|
+
...nitroConfig,
|
|
779
|
+
serveStatic: true,
|
|
780
|
+
rollupConfig: {
|
|
781
|
+
...nitroConfig.rollupConfig,
|
|
782
|
+
output: {
|
|
783
|
+
...nitroConfig.rollupConfig?.output,
|
|
784
|
+
entryFileNames: "server.mjs"
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
hooks: {
|
|
788
|
+
...nitroConfig.hooks,
|
|
789
|
+
compiled: () => {
|
|
790
|
+
if (!hasOutput) {
|
|
791
|
+
const buildOutput = {
|
|
792
|
+
errors: [],
|
|
793
|
+
warnings: [],
|
|
794
|
+
outputPaths: {
|
|
795
|
+
root: pathToFileURL(`${nitroConfig.output?.dir}`),
|
|
796
|
+
browser: pathToFileURL(`${nitroConfig.output?.publicDir}`),
|
|
797
|
+
server: pathToFileURL(`${nitroConfig.output?.dir}/server`)
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
console.log(JSON.stringify(buildOutput, null, 2));
|
|
801
|
+
hasOutput = true;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
};
|
|
695
806
|
};
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
},
|
|
807
|
+
var isNetlifyPreset = (buildPreset) => process.env["NETLIFY"] || buildPreset && buildPreset.toLowerCase().includes("netlify");
|
|
808
|
+
var withNetlifyOutputAPI = (nitroConfig, workspaceRoot) => ({
|
|
809
|
+
...nitroConfig,
|
|
810
|
+
output: {
|
|
811
|
+
...nitroConfig?.output,
|
|
812
|
+
dir: normalizePath(resolve(workspaceRoot, "netlify/functions"))
|
|
813
|
+
}
|
|
704
814
|
});
|
|
815
|
+
//#endregion
|
|
816
|
+
export { nitro };
|
|
817
|
+
|
|
705
818
|
//# sourceMappingURL=vite-plugin-nitro.js.map
|