@nuxt/nitro-server-nightly 0.0.0 → 3.20.1-29360835.617b266c
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/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.mjs +797 -0
- package/dist/runtime/handlers/error.d.ts +3 -0
- package/dist/runtime/handlers/error.js +64 -0
- package/dist/runtime/handlers/island.d.ts +4 -0
- package/dist/runtime/handlers/island.js +102 -0
- package/dist/runtime/handlers/renderer.d.ts +8 -0
- package/dist/runtime/handlers/renderer.js +237 -0
- package/dist/runtime/middleware/no-ssr.d.ts +2 -0
- package/dist/runtime/middleware/no-ssr.js +7 -0
- package/dist/runtime/plugins/dev-server-logs.d.ts +3 -0
- package/dist/runtime/plugins/dev-server-logs.js +82 -0
- package/dist/runtime/templates/error-500.d.ts +2 -0
- package/dist/runtime/templates/error-500.js +6 -0
- package/dist/runtime/utils/cache-driver.d.ts +6 -0
- package/dist/runtime/utils/cache-driver.js +42 -0
- package/dist/runtime/utils/cache.d.ts +8 -0
- package/dist/runtime/utils/cache.js +18 -0
- package/dist/runtime/utils/config.d.ts +1 -0
- package/dist/runtime/utils/config.js +1 -0
- package/dist/runtime/utils/dev.d.ts +1 -0
- package/dist/runtime/utils/dev.js +328 -0
- package/dist/runtime/utils/error.d.ts +6 -0
- package/dist/runtime/utils/error.js +11 -0
- package/dist/runtime/utils/paths.d.ts +4 -0
- package/dist/runtime/utils/paths.js +16 -0
- package/dist/runtime/utils/renderer/app.d.ts +6 -0
- package/dist/runtime/utils/renderer/app.js +32 -0
- package/dist/runtime/utils/renderer/build-files.d.ts +22 -0
- package/dist/runtime/utils/renderer/build-files.js +84 -0
- package/dist/runtime/utils/renderer/inline-styles.d.ts +2 -0
- package/dist/runtime/utils/renderer/inline-styles.js +13 -0
- package/dist/runtime/utils/renderer/islands.d.ts +9 -0
- package/dist/runtime/utils/renderer/islands.js +82 -0
- package/dist/runtime/utils/renderer/payload.d.ts +37 -0
- package/dist/runtime/utils/renderer/payload.js +66 -0
- package/package.json +58 -2
- package/dist/.gitkeep +0 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import { existsSync, promises, readFileSync } from 'node:fs';
|
|
3
|
+
import { cpus } from 'node:os';
|
|
4
|
+
import { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { dirname, relative, resolve, join, isAbsolute } from 'pathe';
|
|
7
|
+
import { readPackageJSON } from 'pkg-types';
|
|
8
|
+
import { toRouteMatcher, createRouter, exportMatcher } from 'radix3';
|
|
9
|
+
import { withTrailingSlash, joinURL } from 'ufo';
|
|
10
|
+
import { createNitro, scanHandlers, writeTypes, copyPublicAssets, prepare, build, prerender, createDevServer } from 'nitropack';
|
|
11
|
+
import { getLayerDirectories, resolveNuxtModule, addTemplate, resolveAlias, addPlugin, resolveIgnorePatterns, createIsIgnored, addVitePlugin, logger, findPath } from '@nuxt/kit';
|
|
12
|
+
import escapeRE from 'escape-string-regexp';
|
|
13
|
+
import { defu } from 'defu';
|
|
14
|
+
import { dynamicEventHandler, defineEventHandler } from 'h3';
|
|
15
|
+
import { isWindows } from 'std-env';
|
|
16
|
+
import { ImpoundPlugin } from 'impound';
|
|
17
|
+
import { resolveModulePath } from 'exsolve';
|
|
18
|
+
|
|
19
|
+
const version = "3.20.1-29360835.617b266c";
|
|
20
|
+
|
|
21
|
+
function toArray(value) {
|
|
22
|
+
return Array.isArray(value) ? value : [value];
|
|
23
|
+
}
|
|
24
|
+
let _distDir = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
if (/(?:chunks|shared)$/.test(_distDir)) {
|
|
26
|
+
_distDir = dirname(_distDir);
|
|
27
|
+
}
|
|
28
|
+
const distDir = _distDir;
|
|
29
|
+
|
|
30
|
+
const template = () => {
|
|
31
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="80" fill="none" class="nuxt-spa-loading" viewBox="0 0 37 25"><path d="M24.236 22.006h10.742L25.563 5.822l-8.979 14.31a4 4 0 0 1-3.388 1.874H2.978l11.631-20 5.897 10.567"/></svg><style>.nuxt-spa-loading{left:50%;position:fixed;top:50%;transform:translate(-50%,-50%)}.nuxt-spa-loading>path{fill:none;stroke:#00dc82;stroke-width:4px;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:128;stroke-dashoffset:128;animation:nuxt-spa-loading-move 3s linear infinite}@keyframes nuxt-spa-loading-move{to{stroke-dashoffset:-128}}</style>';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function createImportProtectionPatterns(nuxt, options) {
|
|
35
|
+
const patterns = [];
|
|
36
|
+
const context = contextFlags[options.context];
|
|
37
|
+
patterns.push([
|
|
38
|
+
/^(nuxt|nuxt3|nuxt-nightly)$/,
|
|
39
|
+
`\`nuxt\`, or \`nuxt-nightly\` cannot be imported directly in ${context}.` + (options.context === "nuxt-app" ? " Instead, import runtime Nuxt composables from `#app` or `#imports`." : "")
|
|
40
|
+
]);
|
|
41
|
+
patterns.push([
|
|
42
|
+
/^((~|~~|@|@@)?\/)?nuxt\.config(\.|$)/,
|
|
43
|
+
"Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module."
|
|
44
|
+
]);
|
|
45
|
+
patterns.push([/(^|node_modules\/)@vue\/composition-api/]);
|
|
46
|
+
for (const mod of nuxt.options.modules.filter((m) => typeof m === "string")) {
|
|
47
|
+
patterns.push([
|
|
48
|
+
new RegExp(`^${escapeRE(mod)}$`),
|
|
49
|
+
"Importing directly from module entry-points is not allowed."
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
for (const i of [/(^|node_modules\/)@nuxt\/(cli|kit|test-utils)/, /(^|node_modules\/)nuxi/, /(^|node_modules\/)nitro(?:pack)?(?:-nightly)?(?:$|\/)(?!(?:dist\/)?(?:node_modules|presets|runtime|types))/, /(^|node_modules\/)nuxt\/(config|kit|schema)/]) {
|
|
53
|
+
patterns.push([i, `This module cannot be imported in ${context}.`]);
|
|
54
|
+
}
|
|
55
|
+
if (options.context === "nitro-app" || options.context === "shared") {
|
|
56
|
+
for (const i of ["#app", /^#build(\/|$)/]) {
|
|
57
|
+
patterns.push([i, `Vue app aliases are not allowed in ${context}.`]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (options.context === "nuxt-app" || options.context === "shared") {
|
|
61
|
+
patterns.push([
|
|
62
|
+
new RegExp(escapeRE(relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, nuxt.options.serverDir || "server"))) + "\\/(api|routes|middleware|plugins)\\/"),
|
|
63
|
+
`Importing from server is not allowed in ${context}.`
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
return patterns;
|
|
67
|
+
}
|
|
68
|
+
const contextFlags = {
|
|
69
|
+
"nitro-app": "server runtime",
|
|
70
|
+
"nuxt-app": "the Vue part of your app",
|
|
71
|
+
"shared": "the #shared directory"
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const nitroSchemaTemplate = {
|
|
75
|
+
filename: "types/nitro-nuxt.d.ts",
|
|
76
|
+
async getContents({ nuxt }) {
|
|
77
|
+
const references = [];
|
|
78
|
+
const declarations = [];
|
|
79
|
+
await nuxt.callHook("nitro:prepare:types", { references, declarations });
|
|
80
|
+
const sourceDir = join(nuxt.options.buildDir, "types");
|
|
81
|
+
const lines = [
|
|
82
|
+
...references.map((ref) => {
|
|
83
|
+
if ("path" in ref && isAbsolute(ref.path)) {
|
|
84
|
+
ref.path = relative(sourceDir, ref.path);
|
|
85
|
+
}
|
|
86
|
+
return `/// <reference ${renderAttrs(ref)} />`;
|
|
87
|
+
}),
|
|
88
|
+
...declarations
|
|
89
|
+
];
|
|
90
|
+
return (
|
|
91
|
+
/* typescript */
|
|
92
|
+
`
|
|
93
|
+
${lines.join("\n")}
|
|
94
|
+
/// <reference path="./schema.d.ts" />
|
|
95
|
+
|
|
96
|
+
import type { RuntimeConfig } from 'nuxt/schema'
|
|
97
|
+
import type { H3Event } from 'h3'
|
|
98
|
+
import type { LogObject } from 'consola'
|
|
99
|
+
import type { NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext } from 'nuxt/app'
|
|
100
|
+
|
|
101
|
+
declare module 'nitropack' {
|
|
102
|
+
interface NitroRuntimeConfigApp {
|
|
103
|
+
buildAssetsDir: string
|
|
104
|
+
cdnURL: string
|
|
105
|
+
}
|
|
106
|
+
interface NitroRuntimeConfig extends RuntimeConfig {}
|
|
107
|
+
interface NitroRouteConfig {
|
|
108
|
+
ssr?: boolean
|
|
109
|
+
noScripts?: boolean
|
|
110
|
+
/** @deprecated Use \`noScripts\` instead */
|
|
111
|
+
experimentalNoScripts?: boolean
|
|
112
|
+
}
|
|
113
|
+
interface NitroRouteRules {
|
|
114
|
+
ssr?: boolean
|
|
115
|
+
noScripts?: boolean
|
|
116
|
+
/** @deprecated Use \`noScripts\` instead */
|
|
117
|
+
experimentalNoScripts?: boolean
|
|
118
|
+
appMiddleware?: Record<string, boolean>
|
|
119
|
+
}
|
|
120
|
+
interface NitroRuntimeHooks {
|
|
121
|
+
'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise<void>
|
|
122
|
+
'render:html': (htmlContext: NuxtRenderHTMLContext, context: { event: H3Event }) => void | Promise<void>
|
|
123
|
+
'render:island': (islandResponse: NuxtIslandResponse, context: { event: H3Event, islandContext: NuxtIslandContext }) => void | Promise<void>
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function renderAttr(key, value) {
|
|
131
|
+
return value ? `${key}="${value}"` : "";
|
|
132
|
+
}
|
|
133
|
+
function renderAttrs(obj) {
|
|
134
|
+
const attrs = [];
|
|
135
|
+
for (const key in obj) {
|
|
136
|
+
attrs.push(renderAttr(key, obj[key]));
|
|
137
|
+
}
|
|
138
|
+
return attrs.join(" ");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const logLevelMapReverse = {
|
|
142
|
+
silent: 0,
|
|
143
|
+
info: 3,
|
|
144
|
+
verbose: 3
|
|
145
|
+
};
|
|
146
|
+
const NODE_MODULES_RE = /(?<=\/)node_modules\/(.+)$/;
|
|
147
|
+
const PNPM_NODE_MODULES_RE = /\.pnpm\/.+\/node_modules\/(.+)$/;
|
|
148
|
+
async function bundle(nuxt) {
|
|
149
|
+
const layerDirs = getLayerDirectories(nuxt);
|
|
150
|
+
const excludePaths = [];
|
|
151
|
+
for (const dirs of layerDirs) {
|
|
152
|
+
const paths = [
|
|
153
|
+
dirs.root.match(NODE_MODULES_RE)?.[1]?.replace(/\/$/, ""),
|
|
154
|
+
dirs.root.match(PNPM_NODE_MODULES_RE)?.[1]?.replace(/\/$/, "")
|
|
155
|
+
];
|
|
156
|
+
for (const dir of paths) {
|
|
157
|
+
if (dir) {
|
|
158
|
+
excludePaths.push(escapeRE(dir));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const layerPublicAssetsDirs = [];
|
|
163
|
+
for (const dirs of layerDirs) {
|
|
164
|
+
if (existsSync(dirs.public)) {
|
|
165
|
+
layerPublicAssetsDirs.push({ dir: dirs.public });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const excludePattern = excludePaths.length ? [new RegExp(`node_modules\\/(?!${excludePaths.join("|")})`)] : [/node_modules/];
|
|
169
|
+
const rootDirWithSlash = withTrailingSlash(nuxt.options.rootDir);
|
|
170
|
+
const moduleEntryPaths = [];
|
|
171
|
+
for (const m of nuxt.options._installedModules) {
|
|
172
|
+
const path = m.meta?.rawPath || m.entryPath;
|
|
173
|
+
if (path) {
|
|
174
|
+
moduleEntryPaths.push(path);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const modules = await resolveNuxtModule(rootDirWithSlash, moduleEntryPaths);
|
|
178
|
+
addTemplate(nitroSchemaTemplate);
|
|
179
|
+
const sharedDirs = /* @__PURE__ */ new Set();
|
|
180
|
+
const isNuxtV4 = nuxt.options.future?.compatibilityVersion === 4;
|
|
181
|
+
if (isNuxtV4 && (nuxt.options.nitro.imports !== false && nuxt.options.imports.scan !== false)) {
|
|
182
|
+
for (const layer of nuxt.options._layers) {
|
|
183
|
+
if (layer.config?.imports?.scan === false) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
sharedDirs.add(resolve(layer.config.rootDir, layer.config.dir?.shared ?? "shared", "utils"));
|
|
187
|
+
sharedDirs.add(resolve(layer.config.rootDir, layer.config.dir?.shared ?? "shared", "types"));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
nuxt.options.nitro.plugins ||= [];
|
|
191
|
+
nuxt.options.nitro.plugins = nuxt.options.nitro.plugins.map((plugin) => plugin ? resolveAlias(plugin, nuxt.options.alias) : plugin);
|
|
192
|
+
if (nuxt.options.dev && nuxt.options.features.devLogs) {
|
|
193
|
+
addPlugin(resolve(nuxt.options.appDir, "plugins/dev-server-logs"));
|
|
194
|
+
nuxt.options.nitro.plugins.push(resolve(distDir, "runtime/plugins/dev-server-logs"));
|
|
195
|
+
nuxt.options.nitro.externals = defu(nuxt.options.nitro.externals, {
|
|
196
|
+
inline: [/#internal\/dev-server-logs-options/]
|
|
197
|
+
});
|
|
198
|
+
nuxt.options.nitro.virtual = defu(nuxt.options.nitro.virtual, {
|
|
199
|
+
"#internal/dev-server-logs-options": () => `export const rootDir = ${JSON.stringify(nuxt.options.rootDir)};`
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (nuxt.options.experimental.componentIslands) {
|
|
203
|
+
nuxt.options.nitro.virtual ||= {};
|
|
204
|
+
nuxt.options.nitro.virtual["#internal/nuxt/island-renderer.mjs"] = () => {
|
|
205
|
+
if (nuxt.options.dev || nuxt.options.experimental.componentIslands !== "auto" || nuxt.apps.default?.pages?.some((p) => p.mode === "server") || nuxt.apps.default?.components?.some((c) => c.mode === "server" && !nuxt.apps.default?.components.some((other) => other.pascalName === c.pascalName && other.mode === "client"))) {
|
|
206
|
+
return `export { default } from '${resolve(distDir, "runtime/handlers/island")}'`;
|
|
207
|
+
}
|
|
208
|
+
return `import { defineEventHandler } from 'h3'; export default defineEventHandler(() => {});`;
|
|
209
|
+
};
|
|
210
|
+
nuxt.options.nitro.handlers ||= [];
|
|
211
|
+
nuxt.options.nitro.handlers.push({
|
|
212
|
+
route: "/__nuxt_island/**",
|
|
213
|
+
handler: "#internal/nuxt/island-renderer.mjs"
|
|
214
|
+
});
|
|
215
|
+
if (!nuxt.options.ssr && nuxt.options.experimental.componentIslands !== "auto") {
|
|
216
|
+
nuxt.options.ssr = true;
|
|
217
|
+
nuxt.options.nitro.routeRules ||= {};
|
|
218
|
+
nuxt.options.nitro.routeRules["/**"] = defu(nuxt.options.nitro.routeRules["/**"], { ssr: false });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const mockProxy = resolveModulePath("mocked-exports/proxy", { from: import.meta.url });
|
|
222
|
+
const { version: nuxtVersion } = await readPackageJSON("nuxt", { from: import.meta.url });
|
|
223
|
+
const nitroConfig = defu(nuxt.options.nitro, {
|
|
224
|
+
debug: nuxt.options.debug ? nuxt.options.debug.nitro : false,
|
|
225
|
+
rootDir: nuxt.options.rootDir,
|
|
226
|
+
workspaceDir: nuxt.options.workspaceDir,
|
|
227
|
+
srcDir: nuxt.options.serverDir,
|
|
228
|
+
dev: nuxt.options.dev,
|
|
229
|
+
buildDir: nuxt.options.buildDir,
|
|
230
|
+
experimental: {
|
|
231
|
+
asyncContext: nuxt.options.experimental.asyncContext,
|
|
232
|
+
typescriptBundlerResolution: nuxt.options.future.typescriptBundlerResolution || nuxt.options.typescript?.tsConfig?.compilerOptions?.moduleResolution?.toLowerCase() === "bundler" || nuxt.options.nitro.typescript?.tsConfig?.compilerOptions?.moduleResolution?.toLowerCase() === "bundler"
|
|
233
|
+
},
|
|
234
|
+
framework: {
|
|
235
|
+
name: "nuxt",
|
|
236
|
+
version: nuxtVersion || version
|
|
237
|
+
},
|
|
238
|
+
imports: {
|
|
239
|
+
autoImport: nuxt.options.imports.autoImport,
|
|
240
|
+
dirs: [...sharedDirs],
|
|
241
|
+
imports: [
|
|
242
|
+
{
|
|
243
|
+
as: "__buildAssetsURL",
|
|
244
|
+
name: "buildAssetsURL",
|
|
245
|
+
from: resolve(distDir, "runtime/utils/paths")
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
as: "__publicAssetsURL",
|
|
249
|
+
name: "publicAssetsURL",
|
|
250
|
+
from: resolve(distDir, "runtime/utils/paths")
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
// TODO: Remove after https://github.com/nitrojs/nitro/issues/1049
|
|
254
|
+
as: "defineAppConfig",
|
|
255
|
+
name: "defineAppConfig",
|
|
256
|
+
from: resolve(distDir, "runtime/utils/config"),
|
|
257
|
+
priority: -1
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
exclude: [...excludePattern, /[\\/]\.git[\\/]/]
|
|
261
|
+
},
|
|
262
|
+
esbuild: {
|
|
263
|
+
options: { exclude: excludePattern }
|
|
264
|
+
},
|
|
265
|
+
analyze: !nuxt.options.test && nuxt.options.build.analyze && (nuxt.options.build.analyze === true || nuxt.options.build.analyze.enabled) ? {
|
|
266
|
+
template: "treemap",
|
|
267
|
+
projectRoot: nuxt.options.rootDir,
|
|
268
|
+
filename: join(nuxt.options.analyzeDir, "{name}.html")
|
|
269
|
+
} : false,
|
|
270
|
+
scanDirs: layerDirs.map((dirs) => dirs.server),
|
|
271
|
+
renderer: resolve(distDir, "runtime/handlers/renderer"),
|
|
272
|
+
errorHandler: resolve(distDir, "runtime/handlers/error"),
|
|
273
|
+
nodeModulesDirs: nuxt.options.modulesDir,
|
|
274
|
+
handlers: nuxt.options.serverHandlers,
|
|
275
|
+
devHandlers: [],
|
|
276
|
+
baseURL: nuxt.options.app.baseURL,
|
|
277
|
+
virtual: {
|
|
278
|
+
"#internal/nuxt.config.mjs": () => nuxt.vfs["#build/nuxt.config.mjs"],
|
|
279
|
+
"#spa-template": async () => `export const template = ${JSON.stringify(await spaLoadingTemplate(nuxt))}`,
|
|
280
|
+
// this will be overridden in vite plugin
|
|
281
|
+
"#internal/entry-chunk.mjs": () => `export const entryFileName = undefined`,
|
|
282
|
+
"#internal/nuxt/entry-ids.mjs": () => `export default []`
|
|
283
|
+
},
|
|
284
|
+
routeRules: {
|
|
285
|
+
"/__nuxt_error": { cache: false }
|
|
286
|
+
},
|
|
287
|
+
appConfig: nuxt.options.appConfig,
|
|
288
|
+
appConfigFiles: layerDirs.map((dirs) => join(dirs.app, "app.config")),
|
|
289
|
+
typescript: {
|
|
290
|
+
strict: true,
|
|
291
|
+
generateTsConfig: true,
|
|
292
|
+
tsconfigPath: "tsconfig.server.json",
|
|
293
|
+
tsConfig: {
|
|
294
|
+
compilerOptions: {
|
|
295
|
+
lib: ["esnext", "webworker", "dom.iterable"]
|
|
296
|
+
},
|
|
297
|
+
include: [
|
|
298
|
+
join(nuxt.options.buildDir, "types/nitro-nuxt.d.ts"),
|
|
299
|
+
...modules.flatMap((m) => {
|
|
300
|
+
const moduleDir = relativeWithDot(nuxt.options.buildDir, m);
|
|
301
|
+
return [
|
|
302
|
+
join(moduleDir, "runtime/server"),
|
|
303
|
+
join(moduleDir, "dist/runtime/server")
|
|
304
|
+
];
|
|
305
|
+
}),
|
|
306
|
+
...layerDirs.map((dirs) => relativeWithDot(nuxt.options.buildDir, join(dirs.shared, "**/*.d.ts")))
|
|
307
|
+
],
|
|
308
|
+
exclude: [
|
|
309
|
+
...nuxt.options.modulesDir.map((m) => relativeWithDot(nuxt.options.buildDir, m)),
|
|
310
|
+
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
311
|
+
relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, "dist"))
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
publicAssets: [
|
|
316
|
+
nuxt.options.dev ? { dir: resolve(nuxt.options.buildDir, "dist/client") } : {
|
|
317
|
+
dir: join(nuxt.options.buildDir, "dist/client", nuxt.options.app.buildAssetsDir),
|
|
318
|
+
maxAge: 31536e3,
|
|
319
|
+
baseURL: nuxt.options.app.buildAssetsDir
|
|
320
|
+
},
|
|
321
|
+
...layerPublicAssetsDirs
|
|
322
|
+
],
|
|
323
|
+
prerender: {
|
|
324
|
+
ignoreUnprefixedPublicAssets: true,
|
|
325
|
+
failOnError: true,
|
|
326
|
+
concurrency: cpus().length * 4 || 4,
|
|
327
|
+
routes: [].concat(nuxt.options.generate.routes)
|
|
328
|
+
},
|
|
329
|
+
sourceMap: nuxt.options.sourcemap.server,
|
|
330
|
+
externals: {
|
|
331
|
+
inline: [
|
|
332
|
+
...nuxt.options.dev ? [] : [
|
|
333
|
+
...nuxt.options.experimental.externalVue ? [] : ["vue", "@vue/"],
|
|
334
|
+
"@nuxt/",
|
|
335
|
+
nuxt.options.buildDir
|
|
336
|
+
],
|
|
337
|
+
...nuxt.options.build.transpile.filter((i) => typeof i === "string"),
|
|
338
|
+
"nuxt/dist",
|
|
339
|
+
"nuxt3/dist",
|
|
340
|
+
"nuxt-nightly/dist",
|
|
341
|
+
distDir,
|
|
342
|
+
// Ensure app config files have auto-imports injected even if they are pure .js files
|
|
343
|
+
...layerDirs.map((dirs) => join(dirs.app, "app.config"))
|
|
344
|
+
],
|
|
345
|
+
traceInclude: [
|
|
346
|
+
// force include files used in generated code from the runtime-compiler
|
|
347
|
+
...nuxt.options.vue.runtimeCompiler && !nuxt.options.experimental.externalVue ? [
|
|
348
|
+
...nuxt.options.modulesDir.reduce((targets, path) => {
|
|
349
|
+
const serverRendererPath = resolve(path, "vue/server-renderer/index.js");
|
|
350
|
+
if (existsSync(serverRendererPath)) {
|
|
351
|
+
targets.push(serverRendererPath);
|
|
352
|
+
}
|
|
353
|
+
return targets;
|
|
354
|
+
}, [])
|
|
355
|
+
] : []
|
|
356
|
+
]
|
|
357
|
+
},
|
|
358
|
+
alias: {
|
|
359
|
+
// Vue 3 mocks
|
|
360
|
+
...nuxt.options.vue.runtimeCompiler || nuxt.options.experimental.externalVue ? {} : {
|
|
361
|
+
"estree-walker": mockProxy,
|
|
362
|
+
"@babel/parser": mockProxy,
|
|
363
|
+
"@vue/compiler-core": mockProxy,
|
|
364
|
+
"@vue/compiler-dom": mockProxy,
|
|
365
|
+
"@vue/compiler-ssr": mockProxy
|
|
366
|
+
},
|
|
367
|
+
"@vue/devtools-api": "vue-devtools-stub",
|
|
368
|
+
// Nuxt aliases
|
|
369
|
+
...nuxt.options.alias,
|
|
370
|
+
// Paths
|
|
371
|
+
"#internal/nuxt/paths": resolve(distDir, "runtime/utils/paths")
|
|
372
|
+
},
|
|
373
|
+
replace: {
|
|
374
|
+
"process.env.NUXT_NO_SSR": nuxt.options.ssr === false,
|
|
375
|
+
"process.env.NUXT_EARLY_HINTS": nuxt.options.experimental.writeEarlyHints !== false,
|
|
376
|
+
"process.env.NUXT_NO_SCRIPTS": String(nuxt.options.features.noScripts === "all" || !!nuxt.options.features.noScripts && !nuxt.options.dev),
|
|
377
|
+
"process.env.NUXT_INLINE_STYLES": !!nuxt.options.features.inlineStyles,
|
|
378
|
+
"process.env.PARSE_ERROR_DATA": String(!!nuxt.options.experimental.parseErrorData),
|
|
379
|
+
"process.env.NUXT_JSON_PAYLOADS": !!nuxt.options.experimental.renderJsonPayloads,
|
|
380
|
+
"process.env.NUXT_ASYNC_CONTEXT": !!nuxt.options.experimental.asyncContext,
|
|
381
|
+
"process.env.NUXT_SHARED_DATA": !!nuxt.options.experimental.sharedPrerenderData,
|
|
382
|
+
"process.dev": nuxt.options.dev,
|
|
383
|
+
"__VUE_PROD_DEVTOOLS__": false
|
|
384
|
+
},
|
|
385
|
+
rollupConfig: {
|
|
386
|
+
output: {
|
|
387
|
+
generatedCode: {
|
|
388
|
+
symbols: true
|
|
389
|
+
// temporary fix for https://github.com/vuejs/core/issues/8351
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
plugins: []
|
|
393
|
+
},
|
|
394
|
+
logLevel: logLevelMapReverse[nuxt.options.logLevel]
|
|
395
|
+
});
|
|
396
|
+
nitroConfig.srcDir = resolve(nuxt.options.rootDir, nuxt.options.srcDir, nitroConfig.srcDir);
|
|
397
|
+
nitroConfig.ignore ||= [];
|
|
398
|
+
nitroConfig.ignore.push(
|
|
399
|
+
...resolveIgnorePatterns(nitroConfig.srcDir),
|
|
400
|
+
`!${join(nuxt.options.buildDir, "dist/client", nuxt.options.app.buildAssetsDir, "**/*")}`
|
|
401
|
+
);
|
|
402
|
+
if (nuxt.options.experimental.appManifest) {
|
|
403
|
+
const buildId = nuxt.options.runtimeConfig.app.buildId ||= nuxt.options.buildId;
|
|
404
|
+
const buildTimestamp = Date.now();
|
|
405
|
+
const manifestPrefix = joinURL(nuxt.options.app.buildAssetsDir, "builds");
|
|
406
|
+
const tempDir = join(nuxt.options.buildDir, "manifest");
|
|
407
|
+
nitroConfig.prerender ||= {};
|
|
408
|
+
nitroConfig.prerender.ignore ||= [];
|
|
409
|
+
nitroConfig.prerender.ignore.push(joinURL(nuxt.options.app.baseURL, manifestPrefix));
|
|
410
|
+
nitroConfig.publicAssets.unshift(
|
|
411
|
+
// build manifest
|
|
412
|
+
{
|
|
413
|
+
dir: join(tempDir, "meta"),
|
|
414
|
+
maxAge: 31536e3,
|
|
415
|
+
baseURL: joinURL(manifestPrefix, "meta")
|
|
416
|
+
},
|
|
417
|
+
// latest build
|
|
418
|
+
{
|
|
419
|
+
dir: tempDir,
|
|
420
|
+
maxAge: 1,
|
|
421
|
+
baseURL: manifestPrefix
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
nuxt.options.alias["#app-manifest"] = join(tempDir, `meta/${buildId}.json`);
|
|
425
|
+
if (!nuxt.options.dev) {
|
|
426
|
+
nuxt.hook("build:before", async () => {
|
|
427
|
+
await promises.mkdir(join(tempDir, "meta"), { recursive: true });
|
|
428
|
+
await promises.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify({}));
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
if (nuxt.options.future.compatibilityVersion !== 4) {
|
|
432
|
+
nuxt.hook("nitro:config", (config) => {
|
|
433
|
+
for (const value of Object.values(config.routeRules || {})) {
|
|
434
|
+
if ("experimentalNoScripts" in value) {
|
|
435
|
+
value.noScripts = value.experimentalNoScripts;
|
|
436
|
+
delete value.experimentalNoScripts;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
nuxt.hook("nitro:config", (config) => {
|
|
442
|
+
config.alias ||= {};
|
|
443
|
+
config.alias["#app-manifest"] = join(tempDir, `meta/${buildId}.json`);
|
|
444
|
+
const rules = config.routeRules;
|
|
445
|
+
for (const rule in rules) {
|
|
446
|
+
if (!rules[rule].appMiddleware) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const value = rules[rule].appMiddleware;
|
|
450
|
+
if (typeof value === "string") {
|
|
451
|
+
rules[rule].appMiddleware = { [value]: true };
|
|
452
|
+
} else if (Array.isArray(value)) {
|
|
453
|
+
const normalizedRules = {};
|
|
454
|
+
for (const middleware of value) {
|
|
455
|
+
normalizedRules[middleware] = true;
|
|
456
|
+
}
|
|
457
|
+
rules[rule].appMiddleware = normalizedRules;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
nuxt.hook("nitro:init", (nitro2) => {
|
|
462
|
+
nitro2.hooks.hook("rollup:before", async (nitro3) => {
|
|
463
|
+
const routeRules = {};
|
|
464
|
+
const _routeRules = nitro3.options.routeRules;
|
|
465
|
+
const validManifestKeys = /* @__PURE__ */ new Set(["prerender", "redirect", "appMiddleware"]);
|
|
466
|
+
for (const key in _routeRules) {
|
|
467
|
+
if (key === "/__nuxt_error") {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
let hasRules = false;
|
|
471
|
+
const filteredRules = {};
|
|
472
|
+
for (const routeKey in _routeRules[key]) {
|
|
473
|
+
const value = _routeRules[key][routeKey];
|
|
474
|
+
if (value && validManifestKeys.has(routeKey)) {
|
|
475
|
+
if (routeKey === "redirect") {
|
|
476
|
+
filteredRules[routeKey] = typeof value === "string" ? value : value.to;
|
|
477
|
+
} else {
|
|
478
|
+
filteredRules[routeKey] = value;
|
|
479
|
+
}
|
|
480
|
+
hasRules = true;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (hasRules) {
|
|
484
|
+
routeRules[key] = filteredRules;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
488
|
+
const routeRulesMatcher = toRouteMatcher(
|
|
489
|
+
createRouter({ routes: routeRules })
|
|
490
|
+
);
|
|
491
|
+
if (nitro3._prerenderedRoutes?.length) {
|
|
492
|
+
const payloadSuffix = nuxt.options.experimental.renderJsonPayloads ? "/_payload.json" : "/_payload.js";
|
|
493
|
+
for (const route of nitro3._prerenderedRoutes) {
|
|
494
|
+
if (!route.error && route.route.endsWith(payloadSuffix)) {
|
|
495
|
+
const url = route.route.slice(0, -payloadSuffix.length) || "/";
|
|
496
|
+
const rules = defu({}, ...routeRulesMatcher.matchAll(url).reverse());
|
|
497
|
+
if (!rules.prerender) {
|
|
498
|
+
prerenderedRoutes.add(url);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const manifest = {
|
|
504
|
+
id: buildId,
|
|
505
|
+
timestamp: buildTimestamp,
|
|
506
|
+
matcher: exportMatcher(routeRulesMatcher),
|
|
507
|
+
prerendered: nuxt.options.dev ? [] : [...prerenderedRoutes]
|
|
508
|
+
};
|
|
509
|
+
await promises.mkdir(join(tempDir, "meta"), { recursive: true });
|
|
510
|
+
await promises.writeFile(join(tempDir, "latest.json"), JSON.stringify({
|
|
511
|
+
id: buildId,
|
|
512
|
+
timestamp: buildTimestamp
|
|
513
|
+
}));
|
|
514
|
+
await promises.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify(manifest));
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
if (!nuxt.options.experimental.appManifest) {
|
|
519
|
+
nuxt.options.alias["#app-manifest"] = mockProxy;
|
|
520
|
+
}
|
|
521
|
+
const FORWARD_SLASH_RE = /\//g;
|
|
522
|
+
if (!nuxt.options.ssr) {
|
|
523
|
+
nitroConfig.virtual["#build/dist/server/server.mjs"] = "export default () => {}";
|
|
524
|
+
if (process.platform === "win32") {
|
|
525
|
+
nitroConfig.virtual["#build/dist/server/server.mjs".replace(FORWARD_SLASH_RE, "\\")] = "export default () => {}";
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (nuxt.options.dev || nuxt.options.builder === "@nuxt/webpack-builder" || nuxt.options.builder === "@nuxt/rspack-builder") {
|
|
529
|
+
nitroConfig.virtual["#build/dist/server/styles.mjs"] = "export default {}";
|
|
530
|
+
if (process.platform === "win32") {
|
|
531
|
+
nitroConfig.virtual["#build/dist/server/styles.mjs".replace(FORWARD_SLASH_RE, "\\")] = "export default {}";
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (nuxt.options.experimental.respectNoSSRHeader) {
|
|
535
|
+
nitroConfig.handlers ||= [];
|
|
536
|
+
nitroConfig.handlers.push({
|
|
537
|
+
handler: resolve(distDir, "runtime/middleware/no-ssr"),
|
|
538
|
+
middleware: true
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
nitroConfig.rollupConfig.plugins = await nitroConfig.rollupConfig.plugins || [];
|
|
542
|
+
nitroConfig.rollupConfig.plugins = toArray(nitroConfig.rollupConfig.plugins);
|
|
543
|
+
const sharedDir = withTrailingSlash(resolve(nuxt.options.rootDir, nuxt.options.dir.shared));
|
|
544
|
+
const relativeSharedDir = withTrailingSlash(relative(nuxt.options.rootDir, resolve(nuxt.options.rootDir, nuxt.options.dir.shared)));
|
|
545
|
+
const sharedPatterns = [/^#shared\//, new RegExp("^" + escapeRE(sharedDir)), new RegExp("^" + escapeRE(relativeSharedDir))];
|
|
546
|
+
nitroConfig.rollupConfig.plugins.push(
|
|
547
|
+
ImpoundPlugin.rollup({
|
|
548
|
+
cwd: nuxt.options.rootDir,
|
|
549
|
+
include: sharedPatterns,
|
|
550
|
+
patterns: createImportProtectionPatterns(nuxt, { context: "shared" })
|
|
551
|
+
}),
|
|
552
|
+
ImpoundPlugin.rollup({
|
|
553
|
+
cwd: nuxt.options.rootDir,
|
|
554
|
+
patterns: createImportProtectionPatterns(nuxt, { context: "nitro-app" }),
|
|
555
|
+
exclude: [/node_modules[\\/]nitro(?:pack)?(?:-nightly)?[\\/]|(packages|@nuxt)[\\/]nitro-server(?:-nightly)?[\\/](src|dist)[\\/]runtime[\\/]/, ...sharedPatterns]
|
|
556
|
+
})
|
|
557
|
+
);
|
|
558
|
+
const isIgnored = createIsIgnored(nuxt);
|
|
559
|
+
nitroConfig.devStorage ??= {};
|
|
560
|
+
nitroConfig.devStorage.root ??= {
|
|
561
|
+
driver: "fs",
|
|
562
|
+
readOnly: true,
|
|
563
|
+
base: nitroConfig.rootDir,
|
|
564
|
+
watchOptions: {
|
|
565
|
+
ignored: [isIgnored]
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
nitroConfig.devStorage.src ??= {
|
|
569
|
+
driver: "fs",
|
|
570
|
+
readOnly: true,
|
|
571
|
+
base: nitroConfig.srcDir,
|
|
572
|
+
watchOptions: {
|
|
573
|
+
ignored: [isIgnored]
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
await nuxt.callHook("nitro:config", nitroConfig);
|
|
577
|
+
const excludedAlias = [/^@vue\/.*$/, "vue", /vue-router/, "vite/client", "#imports", "vue-demi", /^#app/, "~", "@", "~~", "@@"];
|
|
578
|
+
const basePath = nitroConfig.typescript.tsConfig.compilerOptions?.baseUrl ? resolve(nuxt.options.buildDir, nitroConfig.typescript.tsConfig.compilerOptions?.baseUrl) : nuxt.options.buildDir;
|
|
579
|
+
const aliases = nitroConfig.alias;
|
|
580
|
+
const tsConfig = nitroConfig.typescript.tsConfig;
|
|
581
|
+
tsConfig.compilerOptions ||= {};
|
|
582
|
+
tsConfig.compilerOptions.paths ||= {};
|
|
583
|
+
for (const _alias in aliases) {
|
|
584
|
+
const alias = _alias;
|
|
585
|
+
if (excludedAlias.some((pattern) => typeof pattern === "string" ? alias === pattern : pattern.test(alias))) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (alias in tsConfig.compilerOptions.paths) {
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
const absolutePath = resolve(basePath, aliases[alias]);
|
|
592
|
+
const isDirectory = aliases[alias].endsWith("/") || await promises.stat(absolutePath).then((r) => r.isDirectory()).catch(
|
|
593
|
+
() => null
|
|
594
|
+
/* file does not exist */
|
|
595
|
+
);
|
|
596
|
+
tsConfig.compilerOptions.paths[alias] = [absolutePath];
|
|
597
|
+
if (isDirectory) {
|
|
598
|
+
tsConfig.compilerOptions.paths[`${alias}/*`] = [`${absolutePath}/*`];
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const nitro = await createNitro(nitroConfig, {
|
|
602
|
+
compatibilityDate: nuxt.options.compatibilityDate,
|
|
603
|
+
dotenv: nuxt.options._loadOptions?.dotenv
|
|
604
|
+
});
|
|
605
|
+
const spaLoadingTemplateFilePath = await spaLoadingTemplatePath(nuxt);
|
|
606
|
+
nuxt.hook("builder:watch", async (_event, relativePath) => {
|
|
607
|
+
const path = resolve(nuxt.options.srcDir, relativePath);
|
|
608
|
+
if (path === spaLoadingTemplateFilePath) {
|
|
609
|
+
await nitro.hooks.callHook("rollup:reload");
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
const cacheDir = resolve(nuxt.options.buildDir, "cache/nitro/prerender");
|
|
613
|
+
const cacheDriverPath = join(distDir, "runtime/utils/cache-driver.js");
|
|
614
|
+
await promises.rm(cacheDir, { recursive: true, force: true }).catch(() => {
|
|
615
|
+
});
|
|
616
|
+
nitro.options._config.storage = defu(nitro.options._config.storage, {
|
|
617
|
+
"internal:nuxt:prerender": {
|
|
618
|
+
// TODO: resolve upstream where file URLs are not being resolved/inlined correctly
|
|
619
|
+
driver: isWindows ? pathToFileURL(cacheDriverPath).href : cacheDriverPath,
|
|
620
|
+
base: cacheDir
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
nuxt._nitro = nitro;
|
|
624
|
+
await nuxt.callHook("nitro:init", nitro);
|
|
625
|
+
nitro.vfs = nuxt.vfs = nitro.vfs || nuxt.vfs || {};
|
|
626
|
+
nuxt.hook("close", () => nitro.hooks.callHook("close"));
|
|
627
|
+
nitro.hooks.hook("prerender:routes", (routes) => {
|
|
628
|
+
return nuxt.callHook("prerender:routes", { routes });
|
|
629
|
+
});
|
|
630
|
+
if (nuxt.options.vue.runtimeCompiler) {
|
|
631
|
+
addVitePlugin({
|
|
632
|
+
name: "nuxt:vue:runtime-compiler",
|
|
633
|
+
applyToEnvironment: (environment) => environment.name === "client",
|
|
634
|
+
enforce: "pre",
|
|
635
|
+
resolveId(id, importer) {
|
|
636
|
+
if (id === "vue") {
|
|
637
|
+
return this.resolve("vue/dist/vue.esm-bundler", importer, { skipSelf: true });
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
for (const hook of ["webpack:config", "rspack:config"]) {
|
|
642
|
+
nuxt.hook(hook, (configuration) => {
|
|
643
|
+
const clientConfig = configuration.find((config) => config.name === "client");
|
|
644
|
+
if (!clientConfig.resolve) {
|
|
645
|
+
clientConfig.resolve.alias = {};
|
|
646
|
+
}
|
|
647
|
+
if (Array.isArray(clientConfig.resolve.alias)) {
|
|
648
|
+
clientConfig.resolve.alias.push({
|
|
649
|
+
name: "vue",
|
|
650
|
+
alias: "vue/dist/vue.esm-bundler"
|
|
651
|
+
});
|
|
652
|
+
} else {
|
|
653
|
+
clientConfig.resolve.alias.vue = "vue/dist/vue.esm-bundler";
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const devMiddlewareHandler = dynamicEventHandler();
|
|
659
|
+
nitro.options.devHandlers.unshift({ handler: devMiddlewareHandler });
|
|
660
|
+
nitro.options.devHandlers.push(...nuxt.options.devServerHandlers);
|
|
661
|
+
nitro.options.handlers.unshift({
|
|
662
|
+
route: "/__nuxt_error",
|
|
663
|
+
lazy: true,
|
|
664
|
+
handler: resolve(distDir, "runtime/handlers/renderer")
|
|
665
|
+
});
|
|
666
|
+
if (nuxt.options.experimental.chromeDevtoolsProjectSettings) {
|
|
667
|
+
const cacheDir2 = resolve(nuxt.options.rootDir, "node_modules/.cache/nuxt");
|
|
668
|
+
let projectConfiguration = await readFile(join(cacheDir2, "chrome-workspace.json"), "utf-8").then((r) => JSON.parse(r)).catch(() => null);
|
|
669
|
+
if (!projectConfiguration) {
|
|
670
|
+
projectConfiguration = { uuid: randomUUID() };
|
|
671
|
+
await mkdir(cacheDir2, { recursive: true });
|
|
672
|
+
await writeFile(join(cacheDir2, "chrome-workspace.json"), JSON.stringify(projectConfiguration), "utf-8");
|
|
673
|
+
}
|
|
674
|
+
nitro.options.devHandlers.push({
|
|
675
|
+
route: "/.well-known/appspecific/com.chrome.devtools.json",
|
|
676
|
+
handler: defineEventHandler(() => ({
|
|
677
|
+
workspace: {
|
|
678
|
+
...projectConfiguration,
|
|
679
|
+
root: nuxt.options.rootDir
|
|
680
|
+
}
|
|
681
|
+
}))
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
if (!nuxt.options.dev && nuxt.options.experimental.noVueServer) {
|
|
685
|
+
nitro.hooks.hook("rollup:before", (nitro2) => {
|
|
686
|
+
if (nitro2.options.preset === "nitro-prerender") {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
const nuxtErrorHandler = nitro2.options.handlers.findIndex((h) => h.route === "/__nuxt_error");
|
|
690
|
+
if (nuxtErrorHandler >= 0) {
|
|
691
|
+
nitro2.options.handlers.splice(nuxtErrorHandler, 1);
|
|
692
|
+
}
|
|
693
|
+
nitro2.options.renderer = void 0;
|
|
694
|
+
nitro2.options.errorHandler = "#internal/nitro/error";
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
nuxt.hook("prepare:types", async (opts) => {
|
|
698
|
+
if (!nuxt.options.dev) {
|
|
699
|
+
await scanHandlers(nitro);
|
|
700
|
+
await writeTypes(nitro);
|
|
701
|
+
}
|
|
702
|
+
opts.tsConfig.exclude ||= [];
|
|
703
|
+
opts.tsConfig.exclude.push(relative(nuxt.options.buildDir, resolve(nuxt.options.rootDir, nitro.options.output.dir)));
|
|
704
|
+
opts.references.push({ path: resolve(nuxt.options.buildDir, "types/nitro.d.ts") });
|
|
705
|
+
});
|
|
706
|
+
if (nitro.options.static) {
|
|
707
|
+
nitro.hooks.hook("prerender:routes", (routes) => {
|
|
708
|
+
for (const route of ["/200.html", "/404.html"]) {
|
|
709
|
+
routes.add(route);
|
|
710
|
+
}
|
|
711
|
+
if (!nuxt.options.ssr) {
|
|
712
|
+
routes.add("/index.html");
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
if (!nuxt.options.dev) {
|
|
717
|
+
nitro.hooks.hook("rollup:before", async (nitro2) => {
|
|
718
|
+
await copyPublicAssets(nitro2);
|
|
719
|
+
await nuxt.callHook("nitro:build:public-assets", nitro2);
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
async function symlinkDist() {
|
|
723
|
+
if (nitro.options.static) {
|
|
724
|
+
const distDir2 = resolve(nuxt.options.rootDir, "dist");
|
|
725
|
+
if (!existsSync(distDir2)) {
|
|
726
|
+
await promises.symlink(nitro.options.output.publicDir, distDir2, "junction").catch(() => {
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
nuxt.hook("build:done", async () => {
|
|
732
|
+
await nuxt.callHook("nitro:build:before", nitro);
|
|
733
|
+
await prepare(nitro);
|
|
734
|
+
if (nuxt.options.dev) {
|
|
735
|
+
return build(nitro);
|
|
736
|
+
}
|
|
737
|
+
await prerender(nitro);
|
|
738
|
+
logger.restoreAll();
|
|
739
|
+
await build(nitro);
|
|
740
|
+
logger.wrapAll();
|
|
741
|
+
await symlinkDist();
|
|
742
|
+
});
|
|
743
|
+
if (nuxt.options.dev) {
|
|
744
|
+
for (const builder of ["webpack", "rspack"]) {
|
|
745
|
+
nuxt.hook(`${builder}:compile`, ({ name, compiler }) => {
|
|
746
|
+
if (name === "server") {
|
|
747
|
+
const memfs = compiler.outputFileSystem;
|
|
748
|
+
nitro.options.virtual["#build/dist/server/server.mjs"] = () => memfs.readFileSync(join(nuxt.options.buildDir, "dist/server/server.mjs"), "utf-8");
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
nuxt.hook(`${builder}:compiled`, () => {
|
|
752
|
+
nuxt.server.reload();
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
nuxt.hook("vite:compiled", () => {
|
|
756
|
+
nuxt.server.reload();
|
|
757
|
+
});
|
|
758
|
+
nuxt.hook("server:devHandler", (h) => {
|
|
759
|
+
devMiddlewareHandler.set(h);
|
|
760
|
+
});
|
|
761
|
+
nuxt.server = createDevServer(nitro);
|
|
762
|
+
const waitUntilCompile = new Promise((resolve2) => nitro.hooks.hook("compiled", () => resolve2()));
|
|
763
|
+
nuxt.hook("build:done", () => waitUntilCompile);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
const RELATIVE_RE = /^([^.])/;
|
|
767
|
+
function relativeWithDot(from, to) {
|
|
768
|
+
return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
|
|
769
|
+
}
|
|
770
|
+
async function spaLoadingTemplatePath(nuxt) {
|
|
771
|
+
if (typeof nuxt.options.spaLoadingTemplate === "string") {
|
|
772
|
+
return resolve(nuxt.options.srcDir, nuxt.options.spaLoadingTemplate);
|
|
773
|
+
}
|
|
774
|
+
const possiblePaths = nuxt.options._layers.map((layer) => resolve(layer.config.srcDir, layer.config.dir?.app || "app", "spa-loading-template.html"));
|
|
775
|
+
return await findPath(possiblePaths) ?? resolve(nuxt.options.srcDir, nuxt.options.dir?.app || "app", "spa-loading-template.html");
|
|
776
|
+
}
|
|
777
|
+
async function spaLoadingTemplate(nuxt) {
|
|
778
|
+
if (nuxt.options.spaLoadingTemplate === false) {
|
|
779
|
+
return "";
|
|
780
|
+
}
|
|
781
|
+
const spaLoadingTemplate2 = await spaLoadingTemplatePath(nuxt);
|
|
782
|
+
try {
|
|
783
|
+
if (existsSync(spaLoadingTemplate2)) {
|
|
784
|
+
return readFileSync(spaLoadingTemplate2, "utf-8").trim();
|
|
785
|
+
}
|
|
786
|
+
} catch {
|
|
787
|
+
}
|
|
788
|
+
if (nuxt.options.spaLoadingTemplate === true) {
|
|
789
|
+
return template();
|
|
790
|
+
}
|
|
791
|
+
if (nuxt.options.spaLoadingTemplate) {
|
|
792
|
+
logger.warn(`Could not load custom \`spaLoadingTemplate\` path as it does not exist: \`${nuxt.options.spaLoadingTemplate}\`.`);
|
|
793
|
+
}
|
|
794
|
+
return "";
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
export { bundle };
|