@nuxt/vite-builder-nightly 4.3.0-29465977.c4f46c64 → 4.3.0-29466372.7f503428
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +23 -21
- package/dist/index.mjs +1956 -2335
- package/dist/vite-node-entry.d.mts +4 -3
- package/dist/vite-node-entry.mjs +77 -82
- package/dist/vite-node.d.mts +29 -27
- package/dist/vite-node.mjs +216 -233
- package/package.json +8 -11
- package/dist/index.d.ts +0 -23
- package/dist/vite-node-entry.d.ts +0 -5
- package/dist/vite-node.d.ts +0 -34
package/dist/index.mjs
CHANGED
|
@@ -1,2505 +1,2126 @@
|
|
|
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
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import { createJiti } from
|
|
33
|
-
import {
|
|
34
|
-
import replacePlugin from
|
|
35
|
-
import { defineEnv } from
|
|
36
|
-
import { runtimeDependencies } from
|
|
1
|
+
import { isBuiltin } from "node:module";
|
|
2
|
+
import fs, { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { performance } from "node:perf_hooks";
|
|
4
|
+
import * as vite from "vite";
|
|
5
|
+
import { createBuilder, createLogger, createServer, isCSSRequest, mergeConfig } from "vite";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
7
|
+
import { createIsIgnored, directoryToURL, getLayerDirectories, logger, resolveAlias, resolvePath, tryImportModule, tryUseNuxt, useNitro, useNuxt } from "@nuxt/kit";
|
|
8
|
+
import { findStaticImports, parseNodeModulePath, sanitizeFilePath } from "mlly";
|
|
9
|
+
import viteJsxPlugin from "@vitejs/plugin-vue-jsx";
|
|
10
|
+
import vuePlugin from "@vitejs/plugin-vue";
|
|
11
|
+
import { getQuery, joinURL, parseQuery, parseURL, withLeadingSlash, withTrailingSlash, withoutBase, withoutLeadingSlash } from "ufo";
|
|
12
|
+
import { filename } from "pathe/utils";
|
|
13
|
+
import { resolveModulePath } from "exsolve";
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
|
+
import MagicString from "magic-string";
|
|
16
|
+
import process from "node:process";
|
|
17
|
+
import { mkdir, readFile, rm, unlink, writeFile } from "node:fs/promises";
|
|
18
|
+
import net from "node:net";
|
|
19
|
+
import os from "node:os";
|
|
20
|
+
import { Buffer } from "node:buffer";
|
|
21
|
+
import { createError, defineEventHandler, defineLazyEventHandler, handleCors, setHeader } from "h3";
|
|
22
|
+
import { ViteNodeServer } from "vite-node/server";
|
|
23
|
+
import { normalizeViteManifest, precomputeDependencies } from "vue-bundle-renderer";
|
|
24
|
+
import { hasTTY, isCI, provider } from "std-env";
|
|
25
|
+
import { colorize } from "consola/utils";
|
|
26
|
+
import escapeStringRegexp from "escape-string-regexp";
|
|
27
|
+
import { transform } from "esbuild";
|
|
28
|
+
import { defu } from "defu";
|
|
29
|
+
import { getPort } from "get-port-please";
|
|
30
|
+
import { readTSConfig, resolveTSConfig } from "pkg-types";
|
|
31
|
+
import { serialize } from "seroval";
|
|
32
|
+
import { createJiti } from "jiti";
|
|
33
|
+
import { genArrayFromRaw, genImport, genObjectFromRawEntries } from "knitwork";
|
|
34
|
+
import replacePlugin from "@rollup/plugin-replace";
|
|
35
|
+
import { defineEnv } from "unenv";
|
|
36
|
+
import { runtimeDependencies } from "nuxt/meta";
|
|
37
37
|
|
|
38
|
+
//#region ../nuxt/src/core/utils/plugins.ts
|
|
38
39
|
function isVue(id, opts = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (query.macro && (search === "?macro=true" || !opts.type || opts.type.includes("script"))) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
const type = "setup" in query ? "script" : query.type;
|
|
54
|
-
if (!("vue" in query) || opts.type && !opts.type.includes(type)) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
40
|
+
const { search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
41
|
+
if (id.endsWith(".vue") && !search) return true;
|
|
42
|
+
if (!search) return false;
|
|
43
|
+
const query = parseQuery(search);
|
|
44
|
+
if (query.nuxt_component) return false;
|
|
45
|
+
if (query.macro && (search === "?macro=true" || !opts.type || opts.type.includes("script"))) return true;
|
|
46
|
+
const type = "setup" in query ? "script" : query.type;
|
|
47
|
+
if (!("vue" in query) || opts.type && !opts.type.includes(type)) return false;
|
|
48
|
+
return true;
|
|
58
49
|
}
|
|
59
50
|
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils/index.ts
|
|
60
53
|
const IS_CSS_RE = /\.(?:css|scss|sass|postcss|pcss|less|stylus|styl)(?:\?[^.]+)?$/;
|
|
61
54
|
function isCSS(file) {
|
|
62
|
-
|
|
55
|
+
return IS_CSS_RE.test(file);
|
|
63
56
|
}
|
|
57
|
+
/** @since 3.9.0 */
|
|
64
58
|
function toArray(value) {
|
|
65
|
-
|
|
59
|
+
return Array.isArray(value) ? value : [value];
|
|
66
60
|
}
|
|
67
61
|
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/plugins/dev-style-ssr.ts
|
|
68
64
|
function DevStyleSSRPlugin(options) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
const selectors = [joinURL(options.buildAssetsURL, moduleId), joinURL(options.buildAssetsURL, "@fs", moduleId)];
|
|
83
|
-
return code + selectors.map((selector) => `
|
|
84
|
-
document.querySelectorAll(\`link[href="${selector}"]\`).forEach(i=>i.remove())`).join("");
|
|
85
|
-
}
|
|
86
|
-
};
|
|
65
|
+
return {
|
|
66
|
+
name: "nuxt:dev-style-ssr",
|
|
67
|
+
apply: "serve",
|
|
68
|
+
enforce: "post",
|
|
69
|
+
applyToEnvironment: (environment) => environment.name === "client",
|
|
70
|
+
transform(code, id) {
|
|
71
|
+
if (!isCSS(id) || !code.includes("import.meta.hot")) return;
|
|
72
|
+
let moduleId = id;
|
|
73
|
+
if (moduleId.startsWith(options.srcDir)) moduleId = moduleId.slice(options.srcDir.length);
|
|
74
|
+
return code + [joinURL(options.buildAssetsURL, moduleId), joinURL(options.buildAssetsURL, "@fs", moduleId)].map((selector) => `\ndocument.querySelectorAll(\`link[href="${selector}"]\`).forEach(i=>i.remove())`).join("");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
87
77
|
}
|
|
88
78
|
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/plugins/runtime-paths.ts
|
|
89
81
|
const VITE_ASSET_RE = /__VITE_ASSET__|__VITE_PUBLIC_ASSET__/;
|
|
90
82
|
function RuntimePathsPlugin() {
|
|
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
|
-
};
|
|
83
|
+
let sourcemap;
|
|
84
|
+
return {
|
|
85
|
+
name: "nuxt:runtime-paths-dep",
|
|
86
|
+
enforce: "post",
|
|
87
|
+
applyToEnvironment: (environment) => environment.name === "client",
|
|
88
|
+
configResolved(config) {
|
|
89
|
+
sourcemap = !!config.build.sourcemap;
|
|
90
|
+
},
|
|
91
|
+
transform(code, id) {
|
|
92
|
+
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
93
|
+
if (isCSS(pathname)) return;
|
|
94
|
+
if (pathname.endsWith(".vue")) {
|
|
95
|
+
if (search && parseQuery(search).type === "style") return;
|
|
96
|
+
}
|
|
97
|
+
if (VITE_ASSET_RE.test(code)) {
|
|
98
|
+
const s = new MagicString(code);
|
|
99
|
+
s.prepend("import \"#internal/nuxt/paths\";");
|
|
100
|
+
return {
|
|
101
|
+
code: s.toString(),
|
|
102
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
119
107
|
}
|
|
120
108
|
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/utils/config.ts
|
|
121
111
|
function resolveClientEntry(config) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return input.entry;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
throw new Error("No entry found in rollupOptions.input");
|
|
112
|
+
const input = config.environments.client?.build.rollupOptions.input ?? config.build.rollupOptions.input;
|
|
113
|
+
if (input) {
|
|
114
|
+
if (typeof input === "string") return input;
|
|
115
|
+
if (!Array.isArray(input) && input.entry) return input.entry;
|
|
116
|
+
}
|
|
117
|
+
throw new Error("No entry found in rollupOptions.input");
|
|
132
118
|
}
|
|
133
119
|
function resolveServerEntry(config) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return input.server;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
throw new Error("No entry found in rollupOptions.input");
|
|
120
|
+
const input = config.environments.ssr?.build.rollupOptions.input ?? config.build.rollupOptions.input;
|
|
121
|
+
if (input) {
|
|
122
|
+
if (typeof input === "string") return input;
|
|
123
|
+
if (!Array.isArray(input) && input.server) return input.server;
|
|
124
|
+
}
|
|
125
|
+
throw new Error("No entry found in rollupOptions.input");
|
|
144
126
|
}
|
|
145
127
|
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/plugins/type-check.ts
|
|
146
130
|
const QUERY_RE$2 = /\?.+$/;
|
|
147
131
|
function TypeCheckPlugin(nuxt) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
};
|
|
132
|
+
let entry;
|
|
133
|
+
let sourcemap;
|
|
134
|
+
return {
|
|
135
|
+
name: "nuxt:type-check",
|
|
136
|
+
applyToEnvironment: (environment) => environment.name === "client" && !environment.config.isProduction,
|
|
137
|
+
apply: () => {
|
|
138
|
+
return !nuxt.options.test && nuxt.options.typescript.typeCheck === true;
|
|
139
|
+
},
|
|
140
|
+
configResolved(config) {
|
|
141
|
+
try {
|
|
142
|
+
entry = resolveClientEntry(config);
|
|
143
|
+
sourcemap = !!config.build.sourcemap;
|
|
144
|
+
} catch {
|
|
145
|
+
console.debug("[nuxt:type-check] Could not resolve client entry, type checking will not be applied.");
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
transform(code, id) {
|
|
149
|
+
if (id.replace(QUERY_RE$2, "") !== entry) return;
|
|
150
|
+
const s = new MagicString(code);
|
|
151
|
+
s.prepend("import \"/@vite-plugin-checker-runtime-entry\";\n");
|
|
152
|
+
return {
|
|
153
|
+
code: s.toString(),
|
|
154
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
176
158
|
}
|
|
177
159
|
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/plugins/module-preload-polyfill.ts
|
|
178
162
|
const QUERY_RE$1 = /\?.+$/;
|
|
179
163
|
function ModulePreloadPolyfillPlugin() {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
};
|
|
164
|
+
let isDisabled = false;
|
|
165
|
+
let entry;
|
|
166
|
+
let sourcemap;
|
|
167
|
+
return {
|
|
168
|
+
name: "nuxt:module-preload-polyfill",
|
|
169
|
+
applyToEnvironment: (environment) => environment.name === "client",
|
|
170
|
+
configResolved(config) {
|
|
171
|
+
try {
|
|
172
|
+
isDisabled = config.build.modulePreload === false || config.build.modulePreload.polyfill === false;
|
|
173
|
+
sourcemap = !!config.build.sourcemap;
|
|
174
|
+
entry = resolveClientEntry(config);
|
|
175
|
+
} catch {
|
|
176
|
+
console.debug("[nuxt:module-preload-polyfill] Could not resolve client entry, module preload polyfill will not be injected.");
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
transform(code, id) {
|
|
180
|
+
if (isDisabled || id.replace(QUERY_RE$1, "") !== entry) return;
|
|
181
|
+
const s = new MagicString(code);
|
|
182
|
+
s.prepend("import \"vite/modulepreload-polyfill\";\n");
|
|
183
|
+
return {
|
|
184
|
+
code: s.toString(),
|
|
185
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
};
|
|
207
189
|
}
|
|
208
190
|
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/plugins/vite-node.ts
|
|
209
193
|
function getManifest(nuxt, viteServer, clientEntry) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
...nuxt.options.features.noScripts === "all" ? {} : {
|
|
233
|
-
[clientEntry]: {
|
|
234
|
-
file: clientEntry,
|
|
235
|
-
isEntry: true,
|
|
236
|
-
module: true,
|
|
237
|
-
resourceType: "script"
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
return manifest;
|
|
194
|
+
const css = /* @__PURE__ */ new Set();
|
|
195
|
+
const ssrServer = nuxt.options.experimental.viteEnvironmentApi ? viteServer.environments.ssr : viteServer;
|
|
196
|
+
for (const key of ssrServer.moduleGraph.urlToModuleMap.keys()) if (isCSS(key)) {
|
|
197
|
+
if ("raw" in getQuery(key)) continue;
|
|
198
|
+
const importers = ssrServer.moduleGraph.urlToModuleMap.get(key)?.importers;
|
|
199
|
+
if (importers && [...importers].every((i) => i.id && "raw" in getQuery(i.id))) continue;
|
|
200
|
+
css.add(key);
|
|
201
|
+
}
|
|
202
|
+
return normalizeViteManifest({
|
|
203
|
+
"@vite/client": {
|
|
204
|
+
file: "@vite/client",
|
|
205
|
+
css: [...css],
|
|
206
|
+
module: true,
|
|
207
|
+
isEntry: true
|
|
208
|
+
},
|
|
209
|
+
...nuxt.options.features.noScripts === "all" ? {} : { [clientEntry]: {
|
|
210
|
+
file: clientEntry,
|
|
211
|
+
isEntry: true,
|
|
212
|
+
module: true,
|
|
213
|
+
resourceType: "script"
|
|
214
|
+
} }
|
|
215
|
+
});
|
|
242
216
|
}
|
|
243
217
|
function generateSocketPath() {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
if (!isDocker) {
|
|
258
|
-
return `\0${socketName}.sock`;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return join(os.tmpdir(), `${socketName}.sock`);
|
|
218
|
+
const socketName = `nuxt-vite-node-${`${process.pid}-${Date.now()}`}`;
|
|
219
|
+
if (process.platform === "win32") return join(String.raw`\\.\pipe`, socketName);
|
|
220
|
+
if (process.platform === "linux") {
|
|
221
|
+
if (Number.parseInt(process.versions.node.split(".")[0], 10) >= 20 && provider !== "stackblitz") {
|
|
222
|
+
let isDocker = false;
|
|
223
|
+
try {
|
|
224
|
+
isDocker = fs.existsSync("/.dockerenv") || fs.existsSync("/proc/1/cgroup") && fs.readFileSync("/proc/1/cgroup", "utf8").includes("docker");
|
|
225
|
+
} catch {}
|
|
226
|
+
if (!isDocker) return `\0${socketName}.sock`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return join(os.tmpdir(), `${socketName}.sock`);
|
|
263
230
|
}
|
|
264
231
|
function useInvalidates() {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
markInvalidate(mod);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
invalidates,
|
|
286
|
-
markInvalidate,
|
|
287
|
-
markInvalidates
|
|
288
|
-
};
|
|
232
|
+
const invalidates = /* @__PURE__ */ new Set();
|
|
233
|
+
function markInvalidate(mod) {
|
|
234
|
+
if (!mod.id) return;
|
|
235
|
+
if (invalidates.has(mod.id)) return;
|
|
236
|
+
invalidates.add(mod.id);
|
|
237
|
+
markInvalidates(mod.importers);
|
|
238
|
+
}
|
|
239
|
+
function markInvalidates(mods) {
|
|
240
|
+
if (!mods) return;
|
|
241
|
+
for (const mod of mods) markInvalidate(mod);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
invalidates,
|
|
245
|
+
markInvalidate,
|
|
246
|
+
markInvalidates
|
|
247
|
+
};
|
|
289
248
|
}
|
|
290
249
|
function ViteNodePlugin(nuxt) {
|
|
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
|
-
markInvalidate(mod);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
clientServer.watcher.on("all", (_event, file) => {
|
|
344
|
-
invalidates.add(file);
|
|
345
|
-
markInvalidates(clientServer.moduleGraph.getModulesByFile(normalize(file)));
|
|
346
|
-
});
|
|
347
|
-
},
|
|
348
|
-
async buildEnd() {
|
|
349
|
-
await cleanupSocket();
|
|
350
|
-
}
|
|
351
|
-
};
|
|
250
|
+
let socketServer;
|
|
251
|
+
const socketPath = generateSocketPath();
|
|
252
|
+
const { invalidates, markInvalidate, markInvalidates } = useInvalidates();
|
|
253
|
+
async function cleanupSocket() {
|
|
254
|
+
if (socketServer && socketServer.listening) await new Promise((resolveClose) => socketServer.close(() => resolveClose()));
|
|
255
|
+
if (socketPath && !socketPath.startsWith("\\\\.\\pipe\\")) try {
|
|
256
|
+
await unlink(socketPath);
|
|
257
|
+
} catch {}
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
name: "nuxt:vite-node-server",
|
|
261
|
+
enforce: "post",
|
|
262
|
+
configureServer(clientServer) {
|
|
263
|
+
if (!tryUseNuxt()) return;
|
|
264
|
+
function resolveServer(ssrServer) {
|
|
265
|
+
const viteNodeServerOptions = {
|
|
266
|
+
socketPath,
|
|
267
|
+
root: nuxt.options.srcDir,
|
|
268
|
+
entryPath: resolveServerEntry(ssrServer.config),
|
|
269
|
+
base: ssrServer.config.base || "/_nuxt/",
|
|
270
|
+
maxRetryAttempts: nuxt.options.vite.viteNode?.maxRetryAttempts,
|
|
271
|
+
baseRetryDelay: nuxt.options.vite.viteNode?.baseRetryDelay,
|
|
272
|
+
maxRetryDelay: nuxt.options.vite.viteNode?.maxRetryDelay,
|
|
273
|
+
requestTimeout: nuxt.options.vite.viteNode?.requestTimeout,
|
|
274
|
+
baseURL: nuxt.options.devServer.url
|
|
275
|
+
};
|
|
276
|
+
process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions);
|
|
277
|
+
socketServer = createViteNodeSocketServer(nuxt, ssrServer, clientServer, invalidates, viteNodeServerOptions);
|
|
278
|
+
}
|
|
279
|
+
if (nuxt.options.experimental.viteEnvironmentApi) resolveServer(clientServer);
|
|
280
|
+
else nuxt.hook("vite:serverCreated", (ssrServer, ctx) => ctx.isServer ? resolveServer(ssrServer) : void 0);
|
|
281
|
+
nuxt.hook("close", cleanupSocket);
|
|
282
|
+
const client = nuxt.options.experimental.viteEnvironmentApi ? clientServer.environments.client : clientServer;
|
|
283
|
+
nuxt.hook("app:templatesGenerated", (_app, changedTemplates) => {
|
|
284
|
+
for (const template of changedTemplates) {
|
|
285
|
+
const mods = client.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`);
|
|
286
|
+
for (const mod of mods || []) markInvalidate(mod);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
clientServer.watcher.on("all", (_event, file) => {
|
|
290
|
+
invalidates.add(file);
|
|
291
|
+
markInvalidates(clientServer.moduleGraph.getModulesByFile(normalize(file)));
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
async buildEnd() {
|
|
295
|
+
await cleanupSocket();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
352
298
|
}
|
|
353
299
|
let _node;
|
|
354
300
|
function getNode(server) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
});
|
|
301
|
+
return _node ||= new ViteNodeServer(server, { transformMode: {
|
|
302
|
+
ssr: [/.*/],
|
|
303
|
+
web: []
|
|
304
|
+
} });
|
|
361
305
|
}
|
|
362
306
|
function createViteNodeSocketServer(nuxt, ssrServer, clientServer, invalidates, config) {
|
|
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
|
-
socket.on("close", () => {
|
|
497
|
-
resetBuffer();
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
const currentSocketPath = config.socketPath;
|
|
501
|
-
if (!currentSocketPath) {
|
|
502
|
-
throw new Error("Socket path not configured for ViteNodeSocketServer.");
|
|
503
|
-
}
|
|
504
|
-
if (!currentSocketPath.startsWith("\\\\.\\pipe\\")) {
|
|
505
|
-
try {
|
|
506
|
-
fs.unlinkSync(currentSocketPath);
|
|
507
|
-
} catch (unlinkError) {
|
|
508
|
-
if (unlinkError.code !== "ENOENT") ;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
server.listen(currentSocketPath);
|
|
512
|
-
server.on("error", () => {
|
|
513
|
-
});
|
|
514
|
-
return server;
|
|
307
|
+
const server = net.createServer((socket) => {
|
|
308
|
+
const INITIAL_BUFFER_SIZE = 64 * 1024;
|
|
309
|
+
const MAX_BUFFER_SIZE = 1024 * 1024 * 1024;
|
|
310
|
+
let buffer = Buffer.alloc(INITIAL_BUFFER_SIZE);
|
|
311
|
+
let writeOffset = 0;
|
|
312
|
+
let readOffset = 0;
|
|
313
|
+
socket.setNoDelay(true);
|
|
314
|
+
socket.setKeepAlive(true, 0);
|
|
315
|
+
async function processMessage(request) {
|
|
316
|
+
try {
|
|
317
|
+
switch (request.type) {
|
|
318
|
+
case "manifest": {
|
|
319
|
+
const manifestData = getManifest(nuxt, ssrServer, resolveClientEntry(clientServer.config));
|
|
320
|
+
sendResponse(socket, request.id, manifestData);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
case "invalidates": {
|
|
324
|
+
const responsePayload = Array.from(invalidates);
|
|
325
|
+
invalidates.clear();
|
|
326
|
+
sendResponse(socket, request.id, responsePayload);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
case "resolve": {
|
|
330
|
+
const { id: resolveId, importer } = request.payload;
|
|
331
|
+
if (!resolveId) throw createError({
|
|
332
|
+
status: 400,
|
|
333
|
+
message: "Missing id for resolve"
|
|
334
|
+
});
|
|
335
|
+
const resolvedResult = await (nuxt.options.experimental.viteEnvironmentApi ? ssrServer.environments.ssr.pluginContainer : getNode(ssrServer)).resolveId(resolveId, importer).catch(() => null);
|
|
336
|
+
sendResponse(socket, request.id, resolvedResult);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
case "module": {
|
|
340
|
+
if (request.payload.moduleId === "/") throw createError({
|
|
341
|
+
status: 400,
|
|
342
|
+
message: "Invalid moduleId"
|
|
343
|
+
});
|
|
344
|
+
const response = await (nuxt.options.experimental.viteEnvironmentApi ? ssrServer.environments.ssr : getNode(ssrServer)).fetchModule(request.payload.moduleId).catch(async (err) => {
|
|
345
|
+
const errorData = {
|
|
346
|
+
code: "VITE_ERROR",
|
|
347
|
+
id: request.payload.moduleId,
|
|
348
|
+
stack: err.stack || "",
|
|
349
|
+
message: err.message || ""
|
|
350
|
+
};
|
|
351
|
+
if (err.frame) errorData.frame = err.frame;
|
|
352
|
+
if (!errorData.frame && err.code === "PARSE_ERROR") try {
|
|
353
|
+
errorData.frame = await (nuxt.options.experimental.viteEnvironmentApi ? ssrServer.environments.client : getNode(ssrServer)).transformRequest(request.payload.moduleId).then((res) => `${err.message || ""}\n${res?.code}`).catch(() => void 0);
|
|
354
|
+
} catch {}
|
|
355
|
+
throw createError({
|
|
356
|
+
data: errorData,
|
|
357
|
+
message: err.message || "Error fetching module"
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
sendResponse(socket, request.id, response);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
default: throw createError({
|
|
364
|
+
status: 400,
|
|
365
|
+
message: `Unknown request type: ${request.type}`
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
} catch (error) {
|
|
369
|
+
sendError(socket, request.id, error);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const resetBuffer = () => {
|
|
373
|
+
writeOffset = 0;
|
|
374
|
+
readOffset = 0;
|
|
375
|
+
};
|
|
376
|
+
const compactBuffer = () => {
|
|
377
|
+
if (readOffset > 0) {
|
|
378
|
+
const remainingData = writeOffset - readOffset;
|
|
379
|
+
if (remainingData > 0) buffer.copy(buffer, 0, readOffset, writeOffset);
|
|
380
|
+
writeOffset = remainingData;
|
|
381
|
+
readOffset = 0;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const ensureBufferCapacity = (additionalBytes) => {
|
|
385
|
+
const requiredSize = writeOffset + additionalBytes;
|
|
386
|
+
if (requiredSize > MAX_BUFFER_SIZE) throw new Error(`Buffer size limit exceeded: ${requiredSize} > ${MAX_BUFFER_SIZE}`);
|
|
387
|
+
if (requiredSize > buffer.length) {
|
|
388
|
+
compactBuffer();
|
|
389
|
+
if (writeOffset + additionalBytes > buffer.length) {
|
|
390
|
+
const newSize = Math.min(Math.max(buffer.length * 2, requiredSize), MAX_BUFFER_SIZE);
|
|
391
|
+
const newBuffer = Buffer.alloc(newSize);
|
|
392
|
+
buffer.copy(newBuffer, 0, 0, writeOffset);
|
|
393
|
+
buffer = newBuffer;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
socket.on("data", (data) => {
|
|
398
|
+
try {
|
|
399
|
+
ensureBufferCapacity(data.length);
|
|
400
|
+
data.copy(buffer, writeOffset);
|
|
401
|
+
writeOffset += data.length;
|
|
402
|
+
while (writeOffset - readOffset >= 4) {
|
|
403
|
+
const totalLength = 4 + buffer.readUInt32BE(readOffset);
|
|
404
|
+
if (writeOffset - readOffset < totalLength) break;
|
|
405
|
+
const messageJSON = buffer.subarray(readOffset + 4, readOffset + totalLength).toString("utf-8");
|
|
406
|
+
readOffset += totalLength;
|
|
407
|
+
try {
|
|
408
|
+
const request = JSON.parse(messageJSON);
|
|
409
|
+
processMessage(request).catch((error) => {
|
|
410
|
+
sendError(socket, request?.id || "unknown", error);
|
|
411
|
+
});
|
|
412
|
+
} catch (parseError) {
|
|
413
|
+
const errorMessage = parseError instanceof Error ? parseError.message : "Unknown parse error";
|
|
414
|
+
socket.destroy(/* @__PURE__ */ new Error(`Invalid JSON in message: ${errorMessage}`));
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (readOffset > buffer.length / 2) compactBuffer();
|
|
419
|
+
} catch (error) {
|
|
420
|
+
socket.destroy(error instanceof Error ? error : /* @__PURE__ */ new Error("Buffer management error"));
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
socket.on("error", () => {
|
|
424
|
+
resetBuffer();
|
|
425
|
+
});
|
|
426
|
+
socket.on("close", () => {
|
|
427
|
+
resetBuffer();
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
const currentSocketPath = config.socketPath;
|
|
431
|
+
if (!currentSocketPath) throw new Error("Socket path not configured for ViteNodeSocketServer.");
|
|
432
|
+
if (!currentSocketPath.startsWith("\\\\.\\pipe\\")) try {
|
|
433
|
+
fs.unlinkSync(currentSocketPath);
|
|
434
|
+
} catch (unlinkError) {
|
|
435
|
+
if (unlinkError.code !== "ENOENT") {}
|
|
436
|
+
}
|
|
437
|
+
server.listen(currentSocketPath);
|
|
438
|
+
server.on("error", () => {});
|
|
439
|
+
return server;
|
|
515
440
|
}
|
|
516
441
|
function sendResponse(socket, id, data) {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
442
|
+
try {
|
|
443
|
+
const response = {
|
|
444
|
+
id,
|
|
445
|
+
type: "response",
|
|
446
|
+
data
|
|
447
|
+
};
|
|
448
|
+
const responseJSON = JSON.stringify(response);
|
|
449
|
+
const messageBuffer = Buffer.from(responseJSON, "utf-8");
|
|
450
|
+
const messageLength = messageBuffer.length;
|
|
451
|
+
const fullMessage = Buffer.alloc(4 + messageLength);
|
|
452
|
+
fullMessage.writeUInt32BE(messageLength, 0);
|
|
453
|
+
messageBuffer.copy(fullMessage, 4);
|
|
454
|
+
socket.write(fullMessage, (err) => {
|
|
455
|
+
if (err) {}
|
|
456
|
+
});
|
|
457
|
+
} catch (error) {
|
|
458
|
+
sendError(socket, id, error);
|
|
459
|
+
}
|
|
532
460
|
}
|
|
533
461
|
function sendError(socket, id, error) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
462
|
+
const errorResponse = {
|
|
463
|
+
id,
|
|
464
|
+
type: "error",
|
|
465
|
+
error: {
|
|
466
|
+
message: error.message,
|
|
467
|
+
stack: error.stack,
|
|
468
|
+
status: error.status,
|
|
469
|
+
statusText: error.statusText,
|
|
470
|
+
data: error.data
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
const responseJSON = JSON.stringify(errorResponse);
|
|
474
|
+
const messageBuffer = Buffer.from(responseJSON, "utf-8");
|
|
475
|
+
const messageLength = messageBuffer.length;
|
|
476
|
+
const fullMessage = Buffer.alloc(4 + messageLength);
|
|
477
|
+
fullMessage.writeUInt32BE(messageLength, 0);
|
|
478
|
+
messageBuffer.copy(fullMessage, 4);
|
|
479
|
+
socket.write(fullMessage, (err) => {
|
|
480
|
+
if (err) {}
|
|
481
|
+
});
|
|
553
482
|
}
|
|
554
483
|
async function writeDevServer(nuxt) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
484
|
+
const serverResolvedPath = resolveModulePath("#vite-node-entry", { from: import.meta.url });
|
|
485
|
+
const fetchResolvedPath = resolveModulePath("#vite-node", { from: import.meta.url });
|
|
486
|
+
const serverDist = join(nuxt.options.buildDir, "dist/server");
|
|
487
|
+
await mkdir(serverDist, { recursive: true });
|
|
488
|
+
await Promise.all([
|
|
489
|
+
writeFile(join(serverDist, "server.mjs"), `export { default } from ${JSON.stringify(pathToFileURL(serverResolvedPath).href)}`),
|
|
490
|
+
writeFile(join(serverDist, "client.precomputed.mjs"), `export default undefined`),
|
|
491
|
+
writeFile(join(serverDist, "client.manifest.mjs"), `
|
|
563
492
|
import { viteNodeFetch } from ${JSON.stringify(pathToFileURL(fetchResolvedPath))}
|
|
564
493
|
export default () => viteNodeFetch.getManifest()
|
|
565
494
|
`)
|
|
566
|
-
|
|
495
|
+
]);
|
|
567
496
|
}
|
|
568
497
|
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/plugins/public-dirs.ts
|
|
569
500
|
const PREFIX = "virtual:public?";
|
|
570
501
|
const PREFIX_RE = /^virtual:public\?/;
|
|
571
502
|
const CSS_URL_RE = /url\((\/[^)]+)\)/g;
|
|
572
503
|
const CSS_URL_SINGLE_RE = /url\(\/[^)]+\)/;
|
|
573
504
|
const RENDER_CHUNK_RE = /(?<= = )['"`]/;
|
|
574
505
|
const PublicDirsPlugin = (options) => {
|
|
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
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
return {
|
|
642
|
-
code: s.toString(),
|
|
643
|
-
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
},
|
|
647
|
-
generateBundle(_outputOptions, bundle) {
|
|
648
|
-
for (const [file, chunk] of Object.entries(bundle)) {
|
|
649
|
-
if (!file.endsWith(".css") || chunk.type !== "asset") {
|
|
650
|
-
continue;
|
|
651
|
-
}
|
|
652
|
-
let css = chunk.source.toString();
|
|
653
|
-
let wasReplaced = false;
|
|
654
|
-
for (const [full, url] of css.matchAll(CSS_URL_RE)) {
|
|
655
|
-
if (url && resolveFromPublicAssets(url)) {
|
|
656
|
-
const relativeURL = relative(withLeadingSlash(dirname(file)), url);
|
|
657
|
-
css = css.replace(full, `url(${relativeURL})`);
|
|
658
|
-
wasReplaced = true;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
if (wasReplaced) {
|
|
662
|
-
chunk.source = css;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
];
|
|
506
|
+
const { resolveFromPublicAssets } = useResolveFromPublicAssets();
|
|
507
|
+
let sourcemap;
|
|
508
|
+
return [{
|
|
509
|
+
name: "nuxt:vite-public-dir-resolution-dev",
|
|
510
|
+
apply() {
|
|
511
|
+
return !!options.dev && !!options.baseURL && options.baseURL !== "/";
|
|
512
|
+
},
|
|
513
|
+
transform(code, id) {
|
|
514
|
+
if (!isCSSRequest(id) || !CSS_URL_SINGLE_RE.test(code)) return;
|
|
515
|
+
const s = new MagicString(code);
|
|
516
|
+
for (const [full, url] of code.matchAll(CSS_URL_RE)) if (url && resolveFromPublicAssets(url)) s.replace(full, `url(${options.baseURL}${url})`);
|
|
517
|
+
if (s.hasChanged()) return {
|
|
518
|
+
code: s.toString(),
|
|
519
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}, {
|
|
523
|
+
name: "nuxt:vite-public-dir-resolution",
|
|
524
|
+
configResolved(config) {
|
|
525
|
+
sourcemap = !!config.build.sourcemap;
|
|
526
|
+
},
|
|
527
|
+
load: {
|
|
528
|
+
order: "pre",
|
|
529
|
+
filter: { id: PREFIX_RE },
|
|
530
|
+
handler(id) {
|
|
531
|
+
return `import { publicAssetsURL } from '#internal/nuxt/paths';export default publicAssetsURL(${JSON.stringify(decodeURIComponent(id.slice(15)))})`;
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
resolveId: {
|
|
535
|
+
order: "post",
|
|
536
|
+
filter: { id: { exclude: [
|
|
537
|
+
/^\/__skip_vite$/,
|
|
538
|
+
/^[^/]/,
|
|
539
|
+
/^\/@fs/
|
|
540
|
+
] } },
|
|
541
|
+
handler(id) {
|
|
542
|
+
if (resolveFromPublicAssets(id)) return PREFIX + encodeURIComponent(id);
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
renderChunk(code, chunk) {
|
|
546
|
+
if (!chunk.facadeModuleId?.includes("?inline&used")) return;
|
|
547
|
+
const s = new MagicString(code);
|
|
548
|
+
const q = code.match(RENDER_CHUNK_RE)?.[0] || "\"";
|
|
549
|
+
for (const [full, url] of code.matchAll(CSS_URL_RE)) if (url && resolveFromPublicAssets(url)) s.replace(full, `url(${q} + publicAssetsURL(${q}${url}${q}) + ${q})`);
|
|
550
|
+
if (s.hasChanged()) {
|
|
551
|
+
s.prepend(`import { publicAssetsURL } from '#internal/nuxt/paths';`);
|
|
552
|
+
return {
|
|
553
|
+
code: s.toString(),
|
|
554
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
generateBundle(_outputOptions, bundle$1) {
|
|
559
|
+
for (const [file, chunk] of Object.entries(bundle$1)) {
|
|
560
|
+
if (!file.endsWith(".css") || chunk.type !== "asset") continue;
|
|
561
|
+
let css = chunk.source.toString();
|
|
562
|
+
let wasReplaced = false;
|
|
563
|
+
for (const [full, url] of css.matchAll(CSS_URL_RE)) if (url && resolveFromPublicAssets(url)) {
|
|
564
|
+
const relativeURL = relative(withLeadingSlash(dirname(file)), url);
|
|
565
|
+
css = css.replace(full, `url(${relativeURL})`);
|
|
566
|
+
wasReplaced = true;
|
|
567
|
+
}
|
|
568
|
+
if (wasReplaced) chunk.source = css;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}];
|
|
668
572
|
};
|
|
669
573
|
const PUBLIC_ASSETS_RE = /[?#].*$/;
|
|
670
574
|
function useResolveFromPublicAssets() {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return id;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
return { resolveFromPublicAssets };
|
|
575
|
+
const nitro = useNitro();
|
|
576
|
+
function resolveFromPublicAssets(id) {
|
|
577
|
+
for (const dir of nitro.options.publicAssets) {
|
|
578
|
+
if (!id.startsWith(withTrailingSlash(dir.baseURL || "/"))) continue;
|
|
579
|
+
if (existsSync(id.replace(PUBLIC_ASSETS_RE, "").replace(withTrailingSlash(dir.baseURL || "/"), withTrailingSlash(dir.dir)))) return id;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return { resolveFromPublicAssets };
|
|
684
583
|
}
|
|
685
584
|
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region src/utils/logger.ts
|
|
686
587
|
let duplicateCount = 0;
|
|
687
588
|
let lastType = null;
|
|
688
589
|
let lastMsg = null;
|
|
689
590
|
const logLevelMap = {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
591
|
+
silent: "silent",
|
|
592
|
+
info: "info",
|
|
593
|
+
verbose: "info"
|
|
693
594
|
};
|
|
694
595
|
const logLevelMapReverse = {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
596
|
+
silent: 0,
|
|
597
|
+
error: 1,
|
|
598
|
+
warn: 2,
|
|
599
|
+
info: 3
|
|
699
600
|
};
|
|
700
601
|
const RUNTIME_RESOLVE_REF_RE = /^([^ ]+) referenced in/m;
|
|
701
602
|
function createViteLogger(config, ctx = {}) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
viteLogger.hasWarned = true;
|
|
765
|
-
output("warn", msg, opts);
|
|
766
|
-
warnedMessages.add(msg);
|
|
767
|
-
},
|
|
768
|
-
error(msg, opts) {
|
|
769
|
-
viteLogger.hasWarned = true;
|
|
770
|
-
output("error", msg, opts);
|
|
771
|
-
},
|
|
772
|
-
clearScreen() {
|
|
773
|
-
clear();
|
|
774
|
-
},
|
|
775
|
-
hasErrorLogged(error) {
|
|
776
|
-
return loggedErrors.has(error);
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
return viteLogger;
|
|
603
|
+
const loggedErrors = /* @__PURE__ */ new WeakSet();
|
|
604
|
+
const canClearScreen = hasTTY && !isCI && config.clearScreen;
|
|
605
|
+
const _logger = createLogger();
|
|
606
|
+
const relativeOutDir = relative(config.root, config.build.outDir || "");
|
|
607
|
+
const clear = () => {
|
|
608
|
+
_logger.clearScreen("silent");
|
|
609
|
+
};
|
|
610
|
+
const clearScreen = canClearScreen ? clear : () => {};
|
|
611
|
+
const { resolveFromPublicAssets } = useResolveFromPublicAssets();
|
|
612
|
+
function output(type, msg, options = {}) {
|
|
613
|
+
if (typeof msg === "string" && !process.env.DEBUG) {
|
|
614
|
+
if (msg.startsWith("Sourcemap") && msg.includes("node_modules")) return;
|
|
615
|
+
if (msg.includes("didn't resolve at build time, it will remain unchanged to be resolved at runtime")) {
|
|
616
|
+
const id = msg.trim().match(RUNTIME_RESOLVE_REF_RE)?.[1];
|
|
617
|
+
if (id && resolveFromPublicAssets(id)) return;
|
|
618
|
+
}
|
|
619
|
+
if (type === "info" && ctx.hideOutput && msg.includes(relativeOutDir)) return;
|
|
620
|
+
}
|
|
621
|
+
const sameAsLast = lastType === type && lastMsg === msg;
|
|
622
|
+
if (sameAsLast) {
|
|
623
|
+
duplicateCount += 1;
|
|
624
|
+
clearScreen();
|
|
625
|
+
} else {
|
|
626
|
+
duplicateCount = 0;
|
|
627
|
+
lastType = type;
|
|
628
|
+
lastMsg = msg;
|
|
629
|
+
if (options.clear) clearScreen();
|
|
630
|
+
}
|
|
631
|
+
if (options.error) loggedErrors.add(options.error);
|
|
632
|
+
const prevLevel = logger.level;
|
|
633
|
+
logger.level = logLevelMapReverse[config.logLevel || "info"];
|
|
634
|
+
logger[type](msg + (sameAsLast ? colorize("dim", ` (x${duplicateCount + 1})`) : ""));
|
|
635
|
+
logger.level = prevLevel;
|
|
636
|
+
}
|
|
637
|
+
const warnedMessages = /* @__PURE__ */ new Set();
|
|
638
|
+
const viteLogger = {
|
|
639
|
+
hasWarned: false,
|
|
640
|
+
info(msg, opts) {
|
|
641
|
+
output("info", msg, opts);
|
|
642
|
+
},
|
|
643
|
+
warn(msg, opts) {
|
|
644
|
+
viteLogger.hasWarned = true;
|
|
645
|
+
output("warn", msg, opts);
|
|
646
|
+
},
|
|
647
|
+
warnOnce(msg, opts) {
|
|
648
|
+
if (warnedMessages.has(msg)) return;
|
|
649
|
+
viteLogger.hasWarned = true;
|
|
650
|
+
output("warn", msg, opts);
|
|
651
|
+
warnedMessages.add(msg);
|
|
652
|
+
},
|
|
653
|
+
error(msg, opts) {
|
|
654
|
+
viteLogger.hasWarned = true;
|
|
655
|
+
output("error", msg, opts);
|
|
656
|
+
},
|
|
657
|
+
clearScreen() {
|
|
658
|
+
clear();
|
|
659
|
+
},
|
|
660
|
+
hasErrorLogged(error) {
|
|
661
|
+
return loggedErrors.has(error);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
return viteLogger;
|
|
780
665
|
}
|
|
781
666
|
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/plugins/stable-entry.ts
|
|
782
669
|
function StableEntryPlugin(nuxt) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
},
|
|
822
|
-
writeBundle(_options, bundle) {
|
|
823
|
-
let entry = Object.values(bundle).find((chunk) => chunk.type === "chunk" && chunk.isEntry && chunk.name === "entry")?.fileName;
|
|
824
|
-
const prefix = withoutLeadingSlash(nuxt.options.app.buildAssetsDir);
|
|
825
|
-
if (entry?.startsWith(prefix)) {
|
|
826
|
-
entry = entry.slice(prefix.length);
|
|
827
|
-
}
|
|
828
|
-
entryFileName = entry;
|
|
829
|
-
}
|
|
830
|
-
};
|
|
670
|
+
let sourcemap;
|
|
671
|
+
let entryFileName;
|
|
672
|
+
const nitro = useNitro();
|
|
673
|
+
nitro.options.virtual ||= {};
|
|
674
|
+
nitro.options._config.virtual ||= {};
|
|
675
|
+
nitro.options._config.virtual["#internal/entry-chunk.mjs"] = nitro.options.virtual["#internal/entry-chunk.mjs"] = () => `export const entryFileName = ${JSON.stringify(entryFileName)}`;
|
|
676
|
+
return {
|
|
677
|
+
name: "nuxt:stable-entry",
|
|
678
|
+
configResolved(config) {
|
|
679
|
+
sourcemap = !!config.build.sourcemap;
|
|
680
|
+
},
|
|
681
|
+
apply: () => !nuxt.options.dev && nuxt.options.experimental.entryImportMap,
|
|
682
|
+
applyToEnvironment(environment) {
|
|
683
|
+
if (environment.name !== "client") return false;
|
|
684
|
+
if (environment.config.build.target) {
|
|
685
|
+
if (!toArray(environment.config.build.target).every(isSupported)) return false;
|
|
686
|
+
}
|
|
687
|
+
return toArray(environment.config.build.rollupOptions?.output).some((output) => typeof output?.entryFileNames === "string" && output?.entryFileNames.includes("[hash]"));
|
|
688
|
+
},
|
|
689
|
+
renderChunk(code, chunk, _options, meta) {
|
|
690
|
+
const entry = Object.values(meta.chunks).find((chunk$1) => chunk$1.isEntry && chunk$1.name === "entry")?.fileName;
|
|
691
|
+
if (!entry || !chunk.imports.includes(entry)) return;
|
|
692
|
+
const filename$2 = new RegExp(`(?<=['"])[\\./]*${escapeStringRegexp(basename(entry))}`, "g");
|
|
693
|
+
const s = new MagicString(code);
|
|
694
|
+
s.replaceAll(filename$2, "#entry");
|
|
695
|
+
if (s.hasChanged()) return {
|
|
696
|
+
code: s.toString(),
|
|
697
|
+
map: sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
698
|
+
};
|
|
699
|
+
},
|
|
700
|
+
writeBundle(_options, bundle$1) {
|
|
701
|
+
let entry = Object.values(bundle$1).find((chunk) => chunk.type === "chunk" && chunk.isEntry && chunk.name === "entry")?.fileName;
|
|
702
|
+
const prefix = withoutLeadingSlash(nuxt.options.app.buildAssetsDir);
|
|
703
|
+
if (entry?.startsWith(prefix)) entry = entry.slice(prefix.length);
|
|
704
|
+
entryFileName = entry;
|
|
705
|
+
}
|
|
706
|
+
};
|
|
831
707
|
}
|
|
832
708
|
const supportedEnvironments = {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
709
|
+
chrome: 89,
|
|
710
|
+
edge: 89,
|
|
711
|
+
firefox: 108,
|
|
712
|
+
ie: Infinity,
|
|
713
|
+
ios: 16.4,
|
|
714
|
+
opera: 75,
|
|
715
|
+
safari: 16.4
|
|
840
716
|
};
|
|
841
717
|
function isSupported(target) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
const version = Number(_version);
|
|
848
|
-
return Number.isNaN(version) || Number(version) >= constraint;
|
|
718
|
+
const [engine, _version] = target.split(/(?<=[a-z])(?=\d)/);
|
|
719
|
+
const constraint = supportedEnvironments[engine];
|
|
720
|
+
if (!constraint) return true;
|
|
721
|
+
const version = Number(_version);
|
|
722
|
+
return Number.isNaN(version) || Number(version) >= constraint;
|
|
849
723
|
}
|
|
850
724
|
|
|
725
|
+
//#endregion
|
|
726
|
+
//#region src/plugins/analyze.ts
|
|
851
727
|
async function AnalyzePlugin(nuxt) {
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
},
|
|
885
|
-
visualizer({
|
|
886
|
-
...analyzeOptions,
|
|
887
|
-
filename: "filename" in analyzeOptions && analyzeOptions.filename ? analyzeOptions.filename.replace("{name}", "client") : void 0,
|
|
888
|
-
title: "Client bundle stats",
|
|
889
|
-
gzipSize: true,
|
|
890
|
-
brotliSize: true
|
|
891
|
-
})
|
|
892
|
-
];
|
|
893
|
-
}
|
|
894
|
-
};
|
|
728
|
+
if (nuxt.options.test) return;
|
|
729
|
+
const analyzeOptions = defu({}, nuxt.options.build.analyze);
|
|
730
|
+
if (!analyzeOptions.enabled) return;
|
|
731
|
+
const { visualizer } = await import("rollup-plugin-visualizer");
|
|
732
|
+
return {
|
|
733
|
+
name: "nuxt:analyze",
|
|
734
|
+
applyToEnvironment(environment) {
|
|
735
|
+
if (environment.name !== "client") return false;
|
|
736
|
+
return [{
|
|
737
|
+
name: "nuxt:analyze-minify",
|
|
738
|
+
async generateBundle(_opts, outputBundle) {
|
|
739
|
+
for (const _bundleId in outputBundle) {
|
|
740
|
+
const bundle$1 = outputBundle[_bundleId];
|
|
741
|
+
if (!bundle$1 || bundle$1.type !== "chunk") continue;
|
|
742
|
+
const minifiedModuleEntryPromises = [];
|
|
743
|
+
for (const [moduleId, module] of Object.entries(bundle$1.modules)) minifiedModuleEntryPromises.push(transform(module.code || "", { minify: true }).then((result) => [moduleId, {
|
|
744
|
+
...module,
|
|
745
|
+
code: result.code
|
|
746
|
+
}]));
|
|
747
|
+
bundle$1.modules = Object.fromEntries(await Promise.all(minifiedModuleEntryPromises));
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}, visualizer({
|
|
751
|
+
...analyzeOptions,
|
|
752
|
+
filename: "filename" in analyzeOptions && analyzeOptions.filename ? analyzeOptions.filename.replace("{name}", "client") : void 0,
|
|
753
|
+
title: "Client bundle stats",
|
|
754
|
+
gzipSize: true,
|
|
755
|
+
brotliSize: true
|
|
756
|
+
})];
|
|
757
|
+
}
|
|
758
|
+
};
|
|
895
759
|
}
|
|
896
760
|
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region src/plugins/dev-server.ts
|
|
897
763
|
function DevServerPlugin(nuxt) {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
}
|
|
1005
|
-
return defineEventHandler(async (event) => {
|
|
1006
|
-
const isBasePath = event.path.startsWith(viteServer.config.base);
|
|
1007
|
-
let isViteRoute = isBasePath;
|
|
1008
|
-
if (!isViteRoute) {
|
|
1009
|
-
for (const viteRoute of viteServer.middlewares.stack) {
|
|
1010
|
-
if (viteRoute.route.length > 1 && event.path.startsWith(viteRoute.route)) {
|
|
1011
|
-
isViteRoute = true;
|
|
1012
|
-
break;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
isViteRoute ||= isProxyPath(event.path);
|
|
1016
|
-
}
|
|
1017
|
-
if (!isViteRoute) {
|
|
1018
|
-
event.node.req._skip_transform = true;
|
|
1019
|
-
} else if (!useViteCors) {
|
|
1020
|
-
const isPreflight = handleCors(event, nuxt.options.devServer.cors);
|
|
1021
|
-
if (isPreflight) {
|
|
1022
|
-
return null;
|
|
1023
|
-
}
|
|
1024
|
-
setHeader(event, "Vary", "Origin");
|
|
1025
|
-
}
|
|
1026
|
-
const _originalPath = event.node.req.url;
|
|
1027
|
-
await new Promise((resolve, reject) => {
|
|
1028
|
-
viteServer.middlewares.handle(event.node.req, event.node.res, (err) => {
|
|
1029
|
-
event.node.req.url = _originalPath;
|
|
1030
|
-
return err ? reject(err) : resolve(null);
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
|
-
const ended = event.node.res.writableEnded || event.handled;
|
|
1034
|
-
if (!ended && event.path.startsWith(nuxt.options.app.buildAssetsDir) && !staticBases.some((baseURL) => event.path.startsWith(baseURL)) && !devHandlerRegexes.some((regex) => regex.test(event.path))) {
|
|
1035
|
-
throw createError({ status: 404 });
|
|
1036
|
-
}
|
|
1037
|
-
});
|
|
1038
|
-
});
|
|
1039
|
-
await nuxt.callHook("server:devHandler", viteMiddleware);
|
|
1040
|
-
}
|
|
1041
|
-
};
|
|
764
|
+
let useViteCors = false;
|
|
765
|
+
const nitro = useNitro();
|
|
766
|
+
return {
|
|
767
|
+
name: "nuxt:dev-server",
|
|
768
|
+
async config(config) {
|
|
769
|
+
for (const item of [
|
|
770
|
+
config.optimizeDeps,
|
|
771
|
+
config.environments?.client?.optimizeDeps,
|
|
772
|
+
config.environments?.ssr?.optimizeDeps
|
|
773
|
+
]) {
|
|
774
|
+
if (!item) continue;
|
|
775
|
+
const exclude = new Set(item.exclude ?? []);
|
|
776
|
+
item.include = item.include?.filter((dep) => !exclude.has(dep));
|
|
777
|
+
}
|
|
778
|
+
if (!nuxt.options.dev && config.server) config.server.hmr = false;
|
|
779
|
+
useViteCors = config.server?.cors !== void 0;
|
|
780
|
+
if (!useViteCors) {
|
|
781
|
+
config.server ??= {};
|
|
782
|
+
config.server.cors = false;
|
|
783
|
+
}
|
|
784
|
+
if (config.server && config.server.hmr !== false) {
|
|
785
|
+
const serverDefaults = { hmr: { protocol: nuxt.options.devServer.https ? "wss" : void 0 } };
|
|
786
|
+
if (typeof config.server.hmr !== "object" || !config.server.hmr.server) {
|
|
787
|
+
serverDefaults.hmr ??= {};
|
|
788
|
+
const hmrPortDefault = 24678;
|
|
789
|
+
serverDefaults.hmr.port = await getPort({
|
|
790
|
+
verbose: false,
|
|
791
|
+
portRange: [hmrPortDefault, hmrPortDefault + 20]
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
if (nuxt.options.devServer.https) serverDefaults.https = nuxt.options.devServer.https === true ? {} : nuxt.options.devServer.https;
|
|
795
|
+
config.server = defu(config.server, serverDefaults);
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
async configureServer(viteServer) {
|
|
799
|
+
nuxt.hook("app:templatesGenerated", async (_app, changedTemplates) => {
|
|
800
|
+
await Promise.all(changedTemplates.map(async (template) => {
|
|
801
|
+
for (const mod of viteServer.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`) || []) {
|
|
802
|
+
viteServer.moduleGraph.invalidateModule(mod);
|
|
803
|
+
await viteServer.reloadModule(mod);
|
|
804
|
+
}
|
|
805
|
+
}));
|
|
806
|
+
});
|
|
807
|
+
if (nuxt.options.experimental.viteEnvironmentApi) await nuxt.callHook("vite:serverCreated", viteServer, {
|
|
808
|
+
isClient: true,
|
|
809
|
+
isServer: true
|
|
810
|
+
});
|
|
811
|
+
const mw = {
|
|
812
|
+
route: "",
|
|
813
|
+
handle: (req, res, next) => {
|
|
814
|
+
if (req._skip_transform && req.url) req.url = joinURL("/__skip_vite", req.url.replace(/\?.*/, ""));
|
|
815
|
+
next();
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
const transformHandler = viteServer.middlewares.stack.findIndex((m) => m.handle instanceof Function && m.handle.name === "viteTransformMiddleware");
|
|
819
|
+
if (transformHandler === -1) viteServer.middlewares.stack.push(mw);
|
|
820
|
+
else viteServer.middlewares.stack.splice(transformHandler, 0, mw);
|
|
821
|
+
const staticBases = [];
|
|
822
|
+
for (const folder of nitro.options.publicAssets) if (folder.baseURL && folder.baseURL !== "/" && folder.baseURL.startsWith(nuxt.options.app.buildAssetsDir)) staticBases.push(folder.baseURL.replace(/\/?$/, "/"));
|
|
823
|
+
const devHandlerRegexes = [];
|
|
824
|
+
for (const handler of nuxt.options.devServerHandlers) if (handler.route && handler.route !== "/" && handler.route.startsWith(nuxt.options.app.buildAssetsDir)) devHandlerRegexes.push(/* @__PURE__ */ new RegExp(`^${handler.route.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/:[^/]+/g, "[^/]+").replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*")}$`));
|
|
825
|
+
const viteMiddleware = defineLazyEventHandler(() => {
|
|
826
|
+
const proxyConfig = viteServer.config.server.proxy;
|
|
827
|
+
const proxyPatterns = [];
|
|
828
|
+
if (proxyConfig) for (const key in proxyConfig) if (key.startsWith("^")) try {
|
|
829
|
+
proxyPatterns.push({
|
|
830
|
+
type: "regex",
|
|
831
|
+
value: new RegExp(key)
|
|
832
|
+
});
|
|
833
|
+
} catch {}
|
|
834
|
+
else proxyPatterns.push({
|
|
835
|
+
type: "string",
|
|
836
|
+
value: key
|
|
837
|
+
});
|
|
838
|
+
function isProxyPath(path) {
|
|
839
|
+
for (const pattern of proxyPatterns) if (pattern.type === "regex" && pattern.value.test(path)) return true;
|
|
840
|
+
else if (pattern.type === "string" && path.startsWith(pattern.value)) return true;
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
return defineEventHandler(async (event) => {
|
|
844
|
+
let isViteRoute = event.path.startsWith(viteServer.config.base);
|
|
845
|
+
if (!isViteRoute) {
|
|
846
|
+
for (const viteRoute of viteServer.middlewares.stack) if (viteRoute.route.length > 1 && event.path.startsWith(viteRoute.route)) {
|
|
847
|
+
isViteRoute = true;
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
isViteRoute ||= isProxyPath(event.path);
|
|
851
|
+
}
|
|
852
|
+
if (!isViteRoute) event.node.req._skip_transform = true;
|
|
853
|
+
else if (!useViteCors) {
|
|
854
|
+
if (handleCors(event, nuxt.options.devServer.cors)) return null;
|
|
855
|
+
setHeader(event, "Vary", "Origin");
|
|
856
|
+
}
|
|
857
|
+
const _originalPath = event.node.req.url;
|
|
858
|
+
await new Promise((resolve$1, reject) => {
|
|
859
|
+
viteServer.middlewares.handle(event.node.req, event.node.res, (err) => {
|
|
860
|
+
event.node.req.url = _originalPath;
|
|
861
|
+
return err ? reject(err) : resolve$1(null);
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
if (!(event.node.res.writableEnded || event.handled) && event.path.startsWith(nuxt.options.app.buildAssetsDir) && !staticBases.some((baseURL) => event.path.startsWith(baseURL)) && !devHandlerRegexes.some((regex) => regex.test(event.path))) throw createError({ status: 404 });
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
await nuxt.callHook("server:devHandler", viteMiddleware);
|
|
868
|
+
}
|
|
869
|
+
};
|
|
1042
870
|
}
|
|
1043
871
|
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region src/plugins/vite-plugin-checker.ts
|
|
1044
874
|
async function VitePluginCheckerPlugin(nuxt, environment) {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
tsconfigPath,
|
|
1057
|
-
buildMode: supportsProjects
|
|
1058
|
-
}
|
|
1059
|
-
})
|
|
1060
|
-
}));
|
|
1061
|
-
}
|
|
875
|
+
if (!nuxt.options.test && (nuxt.options.typescript.typeCheck === true || nuxt.options.typescript.typeCheck === "build" && !nuxt.options.dev)) {
|
|
876
|
+
const [checker, tsconfigPath] = await Promise.all([import("vite-plugin-checker").then((r) => r.default), resolveTSConfig(nuxt.options.rootDir)]);
|
|
877
|
+
const supportsProjects = await readTSConfig(tsconfigPath).then((r) => !!r.references?.length);
|
|
878
|
+
return ["client", nuxt.options.ssr ? "ssr" : void 0].filter((name) => environment ? name === environment : !!name).map((envName) => ({
|
|
879
|
+
applyToEnvironment: (environment$1) => environment$1.name === envName,
|
|
880
|
+
...checker({ vueTsc: {
|
|
881
|
+
tsconfigPath,
|
|
882
|
+
buildMode: supportsProjects
|
|
883
|
+
} })
|
|
884
|
+
}));
|
|
885
|
+
}
|
|
1062
886
|
}
|
|
1063
887
|
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region src/utils/transpile.ts
|
|
1064
890
|
function getTranspilePatterns(envs) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
} else if (pattern instanceof RegExp) {
|
|
1077
|
-
transpile.push(pattern);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
return transpile;
|
|
891
|
+
const nuxt = useNuxt();
|
|
892
|
+
const transpile = [];
|
|
893
|
+
for (let pattern of nuxt.options.build.transpile) {
|
|
894
|
+
if (typeof pattern === "function") {
|
|
895
|
+
const result = pattern(envs);
|
|
896
|
+
if (result) pattern = result;
|
|
897
|
+
}
|
|
898
|
+
if (typeof pattern === "string") transpile.push(new RegExp(escapeStringRegexp(normalize(pattern))));
|
|
899
|
+
else if (pattern instanceof RegExp) transpile.push(pattern);
|
|
900
|
+
}
|
|
901
|
+
return transpile;
|
|
1081
902
|
}
|
|
903
|
+
/**
|
|
904
|
+
* Get transpile patterns as strings for use with Vite's optimizeDeps.exclude
|
|
905
|
+
* This resolves functions and filters to only string patterns
|
|
906
|
+
*/
|
|
1082
907
|
function getTranspileStrings(envs) {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
patterns.push(normalize(pattern));
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
return patterns;
|
|
908
|
+
const nuxt = useNuxt();
|
|
909
|
+
const patterns = [];
|
|
910
|
+
for (let pattern of nuxt.options.build.transpile) {
|
|
911
|
+
if (typeof pattern === "function") {
|
|
912
|
+
const result = pattern(envs);
|
|
913
|
+
if (result) pattern = result;
|
|
914
|
+
}
|
|
915
|
+
if (typeof pattern === "string") patterns.push(normalize(pattern));
|
|
916
|
+
}
|
|
917
|
+
return patterns;
|
|
1097
918
|
}
|
|
1098
919
|
|
|
920
|
+
//#endregion
|
|
921
|
+
//#region src/shared/client.ts
|
|
1099
922
|
const clientEnvironment = (nuxt, entry) => {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
"import.meta.client": true,
|
|
1168
|
-
"import.meta.browser": true,
|
|
1169
|
-
"import.meta.nitro": false,
|
|
1170
|
-
"import.meta.prerender": false,
|
|
1171
|
-
"module.hot": false,
|
|
1172
|
-
...nuxt.options.experimental.clientNodeCompat ? { global: "globalThis" } : {}
|
|
1173
|
-
},
|
|
1174
|
-
build: {
|
|
1175
|
-
sourcemap: nuxt.options.sourcemap.client ? nuxt.options.vite.build?.sourcemap ?? nuxt.options.sourcemap.client : false,
|
|
1176
|
-
manifest: "manifest.json",
|
|
1177
|
-
outDir: resolve(nuxt.options.buildDir, "dist/client"),
|
|
1178
|
-
rollupOptions: {
|
|
1179
|
-
input: { entry }
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
};
|
|
923
|
+
return {
|
|
924
|
+
optimizeDeps: {
|
|
925
|
+
entries: [entry],
|
|
926
|
+
include: [],
|
|
927
|
+
exclude: [
|
|
928
|
+
"vue",
|
|
929
|
+
"@vue/runtime-core",
|
|
930
|
+
"@vue/runtime-dom",
|
|
931
|
+
"@vue/reactivity",
|
|
932
|
+
"@vue/shared",
|
|
933
|
+
"@vue/devtools-api",
|
|
934
|
+
"@vue/test-utils",
|
|
935
|
+
"vue-router",
|
|
936
|
+
"vue-demi",
|
|
937
|
+
"nuxt",
|
|
938
|
+
"nuxt/app",
|
|
939
|
+
"@nuxt/test-utils",
|
|
940
|
+
"@unhead/vue",
|
|
941
|
+
"consola",
|
|
942
|
+
"defu",
|
|
943
|
+
"devalue",
|
|
944
|
+
"get-port-please",
|
|
945
|
+
"h3",
|
|
946
|
+
"hookable",
|
|
947
|
+
"klona",
|
|
948
|
+
"ofetch",
|
|
949
|
+
"pathe",
|
|
950
|
+
"ufo",
|
|
951
|
+
"unctx",
|
|
952
|
+
"unenv",
|
|
953
|
+
"#app-manifest",
|
|
954
|
+
"#imports",
|
|
955
|
+
"#app",
|
|
956
|
+
"#build",
|
|
957
|
+
"#build/*",
|
|
958
|
+
"#components",
|
|
959
|
+
"#head",
|
|
960
|
+
"virtual:nuxt:",
|
|
961
|
+
"virtual:nuxt:*",
|
|
962
|
+
...getTranspileStrings({
|
|
963
|
+
isDev: nuxt.options.dev,
|
|
964
|
+
isClient: true
|
|
965
|
+
})
|
|
966
|
+
]
|
|
967
|
+
},
|
|
968
|
+
define: {
|
|
969
|
+
"process.env.NODE_ENV": JSON.stringify(nuxt.options.vite.mode),
|
|
970
|
+
"process.server": false,
|
|
971
|
+
"process.client": true,
|
|
972
|
+
"process.browser": true,
|
|
973
|
+
"process.nitro": false,
|
|
974
|
+
"process.prerender": false,
|
|
975
|
+
"import.meta.server": false,
|
|
976
|
+
"import.meta.client": true,
|
|
977
|
+
"import.meta.browser": true,
|
|
978
|
+
"import.meta.nitro": false,
|
|
979
|
+
"import.meta.prerender": false,
|
|
980
|
+
"module.hot": false,
|
|
981
|
+
...nuxt.options.experimental.clientNodeCompat ? { global: "globalThis" } : {}
|
|
982
|
+
},
|
|
983
|
+
build: {
|
|
984
|
+
sourcemap: nuxt.options.sourcemap.client ? nuxt.options.vite.build?.sourcemap ?? nuxt.options.sourcemap.client : false,
|
|
985
|
+
manifest: "manifest.json",
|
|
986
|
+
outDir: resolve(nuxt.options.buildDir, "dist/client"),
|
|
987
|
+
rollupOptions: { input: { entry } }
|
|
988
|
+
}
|
|
989
|
+
};
|
|
1183
990
|
};
|
|
1184
991
|
|
|
992
|
+
//#endregion
|
|
993
|
+
//#region src/client.ts
|
|
1185
994
|
async function buildClient(nuxt, ctx) {
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
995
|
+
const clientConfig = vite.mergeConfig(ctx.config, vite.mergeConfig({
|
|
996
|
+
configFile: false,
|
|
997
|
+
base: nuxt.options.dev ? joinURL(nuxt.options.app.baseURL.replace(/^\.\//, "/") || "/", nuxt.options.app.buildAssetsDir) : "./",
|
|
998
|
+
css: { devSourcemap: !!nuxt.options.sourcemap.client },
|
|
999
|
+
cacheDir: resolve(nuxt.options.rootDir, ctx.config.cacheDir ?? "node_modules/.cache/vite", "client"),
|
|
1000
|
+
plugins: [
|
|
1001
|
+
DevStyleSSRPlugin({
|
|
1002
|
+
srcDir: nuxt.options.srcDir,
|
|
1003
|
+
buildAssetsURL: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir)
|
|
1004
|
+
}),
|
|
1005
|
+
RuntimePathsPlugin(),
|
|
1006
|
+
ViteNodePlugin(nuxt),
|
|
1007
|
+
TypeCheckPlugin(nuxt),
|
|
1008
|
+
ModulePreloadPolyfillPlugin(),
|
|
1009
|
+
StableEntryPlugin(nuxt),
|
|
1010
|
+
AnalyzePlugin(nuxt),
|
|
1011
|
+
DevServerPlugin(nuxt),
|
|
1012
|
+
VitePluginCheckerPlugin(nuxt, "client")
|
|
1013
|
+
],
|
|
1014
|
+
appType: "custom",
|
|
1015
|
+
server: {
|
|
1016
|
+
warmup: { clientFiles: [ctx.entry] },
|
|
1017
|
+
middlewareMode: true
|
|
1018
|
+
},
|
|
1019
|
+
...clientEnvironment(nuxt, ctx.entry)
|
|
1020
|
+
}, nuxt.options.vite.$client || {}));
|
|
1021
|
+
clientConfig.customLogger = createViteLogger(clientConfig);
|
|
1022
|
+
await nuxt.callHook("vite:extendConfig", clientConfig, {
|
|
1023
|
+
isClient: true,
|
|
1024
|
+
isServer: false
|
|
1025
|
+
});
|
|
1026
|
+
clientConfig.plugins.unshift(vuePlugin(clientConfig.vue), viteJsxPlugin(clientConfig.vueJsx));
|
|
1027
|
+
await nuxt.callHook("vite:configResolved", clientConfig, {
|
|
1028
|
+
isClient: true,
|
|
1029
|
+
isServer: false
|
|
1030
|
+
});
|
|
1031
|
+
if (nuxt.options.dev) {
|
|
1032
|
+
const viteServer = await vite.createServer(clientConfig);
|
|
1033
|
+
ctx.clientServer = viteServer;
|
|
1034
|
+
nuxt.hook("close", () => viteServer.close());
|
|
1035
|
+
await nuxt.callHook("vite:serverCreated", viteServer, {
|
|
1036
|
+
isClient: true,
|
|
1037
|
+
isServer: false
|
|
1038
|
+
});
|
|
1039
|
+
} else {
|
|
1040
|
+
logger.info("Building client...");
|
|
1041
|
+
const start = Date.now();
|
|
1042
|
+
logger.restoreAll();
|
|
1043
|
+
await vite.build(clientConfig);
|
|
1044
|
+
logger.wrapAll();
|
|
1045
|
+
await nuxt.callHook("vite:compiled");
|
|
1046
|
+
logger.success(`Client built in ${Date.now() - start}ms`);
|
|
1047
|
+
}
|
|
1239
1048
|
}
|
|
1240
1049
|
|
|
1050
|
+
//#endregion
|
|
1051
|
+
//#region src/manifest.ts
|
|
1241
1052
|
async function writeManifest(ctx) {
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
const manifest = normalizeViteManifest(clientManifest);
|
|
1285
|
-
await nuxt.callHook("build:manifest", manifest);
|
|
1286
|
-
const precomputed = precomputeDependencies(manifest);
|
|
1287
|
-
await writeFile(resolve(serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
1288
|
-
await writeFile(resolve(serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
1289
|
-
if (!nuxt.options.dev) {
|
|
1290
|
-
await rm(manifestFile, { force: true });
|
|
1291
|
-
}
|
|
1053
|
+
const { nuxt } = ctx;
|
|
1054
|
+
const devClientManifest = {
|
|
1055
|
+
"@vite/client": {
|
|
1056
|
+
isEntry: true,
|
|
1057
|
+
file: "@vite/client",
|
|
1058
|
+
css: [],
|
|
1059
|
+
module: true,
|
|
1060
|
+
resourceType: "script"
|
|
1061
|
+
},
|
|
1062
|
+
...nuxt.options.features.noScripts === "all" ? {} : { [ctx.entry]: {
|
|
1063
|
+
isEntry: true,
|
|
1064
|
+
file: ctx.entry,
|
|
1065
|
+
module: true,
|
|
1066
|
+
resourceType: "script"
|
|
1067
|
+
} }
|
|
1068
|
+
};
|
|
1069
|
+
const clientDist = resolve(nuxt.options.buildDir, "dist/client");
|
|
1070
|
+
const serverDist = resolve(nuxt.options.buildDir, "dist/server");
|
|
1071
|
+
const manifestFile = resolve(clientDist, "manifest.json");
|
|
1072
|
+
const clientManifest = nuxt.options.dev ? devClientManifest : JSON.parse(readFileSync(manifestFile, "utf-8"));
|
|
1073
|
+
const manifestEntries = Object.values(clientManifest);
|
|
1074
|
+
const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(nuxt.options.app.buildAssetsDir));
|
|
1075
|
+
const BASE_RE = /* @__PURE__ */ new RegExp(`^${escapeStringRegexp(buildAssetsDir)}`);
|
|
1076
|
+
for (const entry of manifestEntries) {
|
|
1077
|
+
entry.file &&= entry.file.replace(BASE_RE, "");
|
|
1078
|
+
for (const item of ["css", "assets"]) entry[item] &&= entry[item].map((i) => i.replace(BASE_RE, ""));
|
|
1079
|
+
}
|
|
1080
|
+
await mkdir(serverDist, { recursive: true });
|
|
1081
|
+
if (ctx.config.build?.cssCodeSplit === false) {
|
|
1082
|
+
for (const entry of manifestEntries) if (entry.file?.endsWith(".css")) {
|
|
1083
|
+
const key = relative(ctx.config.root, ctx.entry);
|
|
1084
|
+
clientManifest[key].css ||= [];
|
|
1085
|
+
clientManifest[key].css.push(entry.file);
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
const manifest = normalizeViteManifest(clientManifest);
|
|
1090
|
+
await nuxt.callHook("build:manifest", manifest);
|
|
1091
|
+
const precomputed = precomputeDependencies(manifest);
|
|
1092
|
+
await writeFile(resolve(serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
1093
|
+
await writeFile(resolve(serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
1094
|
+
if (!nuxt.options.dev) await rm(manifestFile, { force: true });
|
|
1292
1095
|
}
|
|
1293
1096
|
|
|
1097
|
+
//#endregion
|
|
1098
|
+
//#region src/plugins/sourcemap-preserver.ts
|
|
1294
1099
|
const SourcemapPreserverPlugin = (nuxt) => {
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
const dest = id + ".map.json";
|
|
1350
|
-
await mkdir(dirname(dest), { recursive: true });
|
|
1351
|
-
await writeFile(dest, JSON.stringify({
|
|
1352
|
-
file: chunk.map.file,
|
|
1353
|
-
mappings: chunk.map.mappings,
|
|
1354
|
-
names: chunk.map.names,
|
|
1355
|
-
sources: chunk.map.sources,
|
|
1356
|
-
sourcesContent: chunk.map.sourcesContent,
|
|
1357
|
-
version: chunk.map.version
|
|
1358
|
-
}));
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1100
|
+
let outputDir;
|
|
1101
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1102
|
+
if (!nuxt.options.sourcemap.server || nuxt.options.dev) return [];
|
|
1103
|
+
const nitroPlugin = () => ({
|
|
1104
|
+
name: "nuxt:sourcemap-import",
|
|
1105
|
+
load: {
|
|
1106
|
+
filter: { id: /* @__PURE__ */ new RegExp("^(\\w:)?" + escapeStringRegexp(outputDir.replace(/\/?$/, "/")).replace(/\//g, "[\\\\/]")) },
|
|
1107
|
+
async handler(id) {
|
|
1108
|
+
id = resolve(id);
|
|
1109
|
+
if (!ids.has(id)) return;
|
|
1110
|
+
const [code, map] = await Promise.all([readFile(id, "utf-8").catch(() => void 0), readFile(id + ".map.json", "utf-8").catch(() => void 0)]);
|
|
1111
|
+
if (!code) {
|
|
1112
|
+
this.warn("Failed loading file");
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
return {
|
|
1116
|
+
code,
|
|
1117
|
+
map
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
nuxt.hook("nitro:build:before", (nitro) => {
|
|
1123
|
+
nitro.options.rollupConfig = defu(nitro.options.rollupConfig, { plugins: [nitroPlugin] });
|
|
1124
|
+
});
|
|
1125
|
+
return {
|
|
1126
|
+
name: "nuxt:sourcemap-export",
|
|
1127
|
+
applyToEnvironment: (environment) => {
|
|
1128
|
+
return environment.name === "ssr" && environment.config.isProduction;
|
|
1129
|
+
},
|
|
1130
|
+
apply(config) {
|
|
1131
|
+
return !!config.build?.sourcemap;
|
|
1132
|
+
},
|
|
1133
|
+
configResolved(config) {
|
|
1134
|
+
outputDir = config.build.outDir;
|
|
1135
|
+
},
|
|
1136
|
+
async writeBundle(_options, bundle$1) {
|
|
1137
|
+
for (const chunk of Object.values(bundle$1)) {
|
|
1138
|
+
if (chunk.type !== "chunk" || !chunk.map) continue;
|
|
1139
|
+
const id = resolve(outputDir, chunk.fileName);
|
|
1140
|
+
ids.add(id);
|
|
1141
|
+
const dest = id + ".map.json";
|
|
1142
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
1143
|
+
await writeFile(dest, JSON.stringify({
|
|
1144
|
+
file: chunk.map.file,
|
|
1145
|
+
mappings: chunk.map.mappings,
|
|
1146
|
+
names: chunk.map.names,
|
|
1147
|
+
sources: chunk.map.sources,
|
|
1148
|
+
sourcesContent: chunk.map.sourcesContent,
|
|
1149
|
+
version: chunk.map.version
|
|
1150
|
+
}));
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1362
1154
|
};
|
|
1363
1155
|
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region src/plugins/vue-feature-flags.ts
|
|
1364
1158
|
function VueFeatureFlagsPlugin(nuxt) {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1159
|
+
return {
|
|
1160
|
+
name: "nuxt:nitro:vue-feature-flags",
|
|
1161
|
+
applyToEnvironment: (environment) => environment.name === "ssr" && environment.config.isProduction,
|
|
1162
|
+
configResolved(config) {
|
|
1163
|
+
for (const key in config.define) if (key.startsWith("__VUE")) nuxt._nitro.options.replace[key] = config.define[key];
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1376
1166
|
}
|
|
1377
1167
|
|
|
1168
|
+
//#endregion
|
|
1169
|
+
//#region src/shared/server.ts
|
|
1378
1170
|
function ssr(nuxt) {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1171
|
+
return {
|
|
1172
|
+
external: [
|
|
1173
|
+
"nitro/runtime",
|
|
1174
|
+
"#internal/nitro",
|
|
1175
|
+
"#internal/nitro/utils"
|
|
1176
|
+
],
|
|
1177
|
+
noExternal: [
|
|
1178
|
+
...getTranspilePatterns({
|
|
1179
|
+
isServer: true,
|
|
1180
|
+
isDev: nuxt.options.dev
|
|
1181
|
+
}),
|
|
1182
|
+
"/__vue-jsx",
|
|
1183
|
+
"#app",
|
|
1184
|
+
/^nuxt(\/|$)/,
|
|
1185
|
+
/(nuxt|nuxt3|nuxt-nightly)\/(dist|src|app)/
|
|
1186
|
+
]
|
|
1187
|
+
};
|
|
1394
1188
|
}
|
|
1395
1189
|
function ssrEnvironment(nuxt, serverEntry) {
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
include: void 0,
|
|
1453
|
-
exclude: getTranspileStrings({ isDev: nuxt.options.dev, isClient: false })
|
|
1454
|
-
},
|
|
1455
|
-
resolve: {
|
|
1456
|
-
conditions: useNitro().options.exportConditions
|
|
1457
|
-
}
|
|
1458
|
-
};
|
|
1190
|
+
return {
|
|
1191
|
+
build: {
|
|
1192
|
+
reportCompressedSize: false,
|
|
1193
|
+
sourcemap: nuxt.options.sourcemap.server ? nuxt.options.vite.build?.sourcemap ?? nuxt.options.sourcemap.server : false,
|
|
1194
|
+
outDir: resolve(nuxt.options.buildDir, "dist/server"),
|
|
1195
|
+
ssr: true,
|
|
1196
|
+
rollupOptions: {
|
|
1197
|
+
input: { server: serverEntry },
|
|
1198
|
+
external: [
|
|
1199
|
+
"nitro/runtime",
|
|
1200
|
+
"#internal/nitro",
|
|
1201
|
+
"nitropack/runtime",
|
|
1202
|
+
"#internal/nuxt/paths",
|
|
1203
|
+
"#internal/nuxt/app-config",
|
|
1204
|
+
"#app-manifest",
|
|
1205
|
+
"#shared",
|
|
1206
|
+
/* @__PURE__ */ new RegExp("^" + escapeStringRegexp(withTrailingSlash(resolve(nuxt.options.rootDir, nuxt.options.dir.shared))))
|
|
1207
|
+
],
|
|
1208
|
+
output: {
|
|
1209
|
+
entryFileNames: "[name].mjs",
|
|
1210
|
+
format: "module",
|
|
1211
|
+
...vite.rolldownVersion ? {} : { generatedCode: {
|
|
1212
|
+
symbols: true,
|
|
1213
|
+
constBindings: true,
|
|
1214
|
+
arrowFunctions: true
|
|
1215
|
+
} }
|
|
1216
|
+
},
|
|
1217
|
+
onwarn(warning, rollupWarn) {
|
|
1218
|
+
if (warning.code && "UNUSED_EXTERNAL_IMPORT" === warning.code) return;
|
|
1219
|
+
rollupWarn(warning);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
define: {
|
|
1224
|
+
"process.server": true,
|
|
1225
|
+
"process.client": false,
|
|
1226
|
+
"process.browser": false,
|
|
1227
|
+
"import.meta.server": true,
|
|
1228
|
+
"import.meta.client": false,
|
|
1229
|
+
"import.meta.browser": false,
|
|
1230
|
+
"window": "undefined",
|
|
1231
|
+
"document": "undefined",
|
|
1232
|
+
"navigator": "undefined",
|
|
1233
|
+
"location": "undefined",
|
|
1234
|
+
"XMLHttpRequest": "undefined"
|
|
1235
|
+
},
|
|
1236
|
+
optimizeDeps: {
|
|
1237
|
+
noDiscovery: true,
|
|
1238
|
+
include: void 0,
|
|
1239
|
+
exclude: getTranspileStrings({
|
|
1240
|
+
isDev: nuxt.options.dev,
|
|
1241
|
+
isClient: false
|
|
1242
|
+
})
|
|
1243
|
+
},
|
|
1244
|
+
resolve: { conditions: useNitro().options.exportConditions }
|
|
1245
|
+
};
|
|
1459
1246
|
}
|
|
1460
1247
|
|
|
1248
|
+
//#endregion
|
|
1249
|
+
//#region src/server.ts
|
|
1461
1250
|
async function buildServer(nuxt, ctx) {
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
await ssrServer.reloadModule(mod);
|
|
1540
|
-
}
|
|
1541
|
-
}));
|
|
1542
|
-
});
|
|
1543
|
-
await ssrServer.pluginContainer.buildStart({});
|
|
1544
|
-
await writeDevServer(nuxt);
|
|
1251
|
+
const serverEntry = nuxt.options.ssr ? ctx.entry : await resolvePath(resolve(nuxt.options.appDir, "entry-spa"));
|
|
1252
|
+
const serverConfig = vite.mergeConfig(ctx.config, vite.mergeConfig({
|
|
1253
|
+
configFile: false,
|
|
1254
|
+
base: nuxt.options.dev ? joinURL(nuxt.options.app.baseURL.replace(/^\.\//, "/") || "/", nuxt.options.app.buildAssetsDir) : void 0,
|
|
1255
|
+
css: { devSourcemap: !!nuxt.options.sourcemap.server },
|
|
1256
|
+
plugins: [
|
|
1257
|
+
VueFeatureFlagsPlugin(nuxt),
|
|
1258
|
+
SourcemapPreserverPlugin(nuxt),
|
|
1259
|
+
VitePluginCheckerPlugin(nuxt, "ssr"),
|
|
1260
|
+
{
|
|
1261
|
+
name: "nuxt:server-hmr-port",
|
|
1262
|
+
async config(serverConfig$1) {
|
|
1263
|
+
serverConfig$1.server ||= {};
|
|
1264
|
+
serverConfig$1.server.hmr ||= {};
|
|
1265
|
+
if (nuxt.options.dev && typeof serverConfig$1.server.hmr !== "boolean") {
|
|
1266
|
+
const hmrPortDefault = 24678;
|
|
1267
|
+
serverConfig$1.server.hmr.port ||= await getPort({
|
|
1268
|
+
verbose: false,
|
|
1269
|
+
portRange: [hmrPortDefault, hmrPortDefault + 20]
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
],
|
|
1275
|
+
environments: { ssr: { resolve: { conditions: nuxt._nitro?.options.exportConditions } } },
|
|
1276
|
+
ssr: ssr(nuxt),
|
|
1277
|
+
cacheDir: resolve(nuxt.options.rootDir, ctx.config.cacheDir ?? "node_modules/.cache/vite", "server"),
|
|
1278
|
+
server: {
|
|
1279
|
+
warmup: { ssrFiles: [serverEntry] },
|
|
1280
|
+
preTransformRequests: false,
|
|
1281
|
+
hmr: false
|
|
1282
|
+
},
|
|
1283
|
+
...ssrEnvironment(nuxt, serverEntry)
|
|
1284
|
+
}, nuxt.options.vite.$server || {}));
|
|
1285
|
+
serverConfig.customLogger = createViteLogger(serverConfig, { hideOutput: !nuxt.options.dev });
|
|
1286
|
+
await nuxt.callHook("vite:extendConfig", serverConfig, {
|
|
1287
|
+
isClient: false,
|
|
1288
|
+
isServer: true
|
|
1289
|
+
});
|
|
1290
|
+
serverConfig.plugins.unshift(vuePlugin(serverConfig.vue), viteJsxPlugin(serverConfig.vueJsx));
|
|
1291
|
+
await nuxt.callHook("vite:configResolved", serverConfig, {
|
|
1292
|
+
isClient: false,
|
|
1293
|
+
isServer: true
|
|
1294
|
+
});
|
|
1295
|
+
if (!nuxt.options.dev) {
|
|
1296
|
+
const start = Date.now();
|
|
1297
|
+
logger.info("Building server...");
|
|
1298
|
+
logger.restoreAll();
|
|
1299
|
+
await vite.build(serverConfig);
|
|
1300
|
+
logger.wrapAll();
|
|
1301
|
+
await writeManifest(ctx);
|
|
1302
|
+
await nuxt.callHook("vite:compiled");
|
|
1303
|
+
logger.success(`Server built in ${Date.now() - start}ms`);
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
if (!nuxt.options.ssr) {
|
|
1307
|
+
await writeManifest(ctx);
|
|
1308
|
+
await nuxt.callHook("vite:compiled");
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
const ssrServer = await vite.createServer(serverConfig);
|
|
1312
|
+
ctx.ssrServer = ssrServer;
|
|
1313
|
+
nuxt.hook("close", () => ssrServer.close());
|
|
1314
|
+
await nuxt.callHook("vite:serverCreated", ssrServer, {
|
|
1315
|
+
isClient: false,
|
|
1316
|
+
isServer: true
|
|
1317
|
+
});
|
|
1318
|
+
nuxt.hook("app:templatesGenerated", async (_app, changedTemplates) => {
|
|
1319
|
+
await Promise.all(changedTemplates.map(async (template) => {
|
|
1320
|
+
for (const mod of ssrServer.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`) || []) {
|
|
1321
|
+
ssrServer.moduleGraph.invalidateModule(mod);
|
|
1322
|
+
await ssrServer.reloadModule(mod);
|
|
1323
|
+
}
|
|
1324
|
+
}));
|
|
1325
|
+
});
|
|
1326
|
+
await ssrServer.pluginContainer.buildStart({});
|
|
1327
|
+
await writeDevServer(nuxt);
|
|
1545
1328
|
}
|
|
1546
1329
|
|
|
1330
|
+
//#endregion
|
|
1331
|
+
//#region src/utils/warmup.ts
|
|
1547
1332
|
function fileToUrl(file, root) {
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
}
|
|
1552
|
-
return "/" + normalize(url);
|
|
1333
|
+
const url = relative(root, file);
|
|
1334
|
+
if (url[0] === ".") return join("/@fs/", normalize(file));
|
|
1335
|
+
return "/" + normalize(url);
|
|
1553
1336
|
}
|
|
1554
1337
|
function normaliseURL(url, base) {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
url = url.replace(/[?&]import=?(?:&|$)/, "").replace(/[?&]$/, "");
|
|
1560
|
-
return url;
|
|
1338
|
+
url = withoutBase(url, base);
|
|
1339
|
+
if (url.startsWith("/@id/")) url = url.slice(5).replace("__x00__", "\0");
|
|
1340
|
+
url = url.replace(/[?&]import=?(?:&|$)/, "").replace(/[?&]$/, "");
|
|
1341
|
+
return url;
|
|
1561
1342
|
}
|
|
1562
1343
|
async function warmupViteServer(server, entries, isServer) {
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
mod?.importedModules
|
|
1586
|
-
/* client */
|
|
1587
|
-
).map((m) => m.url) : []);
|
|
1588
|
-
await Promise.all(deps.map((m) => warmup(m)));
|
|
1589
|
-
} catch (e) {
|
|
1590
|
-
logger.debug("[warmup] tracking dependencies for %s failed with: %s", url, e);
|
|
1591
|
-
}
|
|
1592
|
-
};
|
|
1593
|
-
await Promise.all(entries.map((entry) => warmup(fileToUrl(entry, server.config.root))));
|
|
1344
|
+
const warmedUrls = /* @__PURE__ */ new Set();
|
|
1345
|
+
const warmup = async (url) => {
|
|
1346
|
+
try {
|
|
1347
|
+
url = normaliseURL(url, server.config.base);
|
|
1348
|
+
if (warmedUrls.has(url) || isBuiltin(url)) return;
|
|
1349
|
+
const m = await server.moduleGraph.getModuleByUrl(url, isServer);
|
|
1350
|
+
if (m?.transformResult?.code || m?.ssrTransformResult?.code) return;
|
|
1351
|
+
warmedUrls.add(url);
|
|
1352
|
+
await server.transformRequest(url, { ssr: isServer });
|
|
1353
|
+
} catch (e) {
|
|
1354
|
+
logger.debug("[nuxt] warmup for %s failed with: %s", url, e);
|
|
1355
|
+
}
|
|
1356
|
+
if (isCSSRequest(url)) return;
|
|
1357
|
+
try {
|
|
1358
|
+
const mod = await server.moduleGraph.getModuleByUrl(url, isServer);
|
|
1359
|
+
const deps = mod?.ssrTransformResult?.deps || (mod?.importedModules.size ? Array.from(mod?.importedModules).map((m) => m.url) : []);
|
|
1360
|
+
await Promise.all(deps.map((m) => warmup(m)));
|
|
1361
|
+
} catch (e) {
|
|
1362
|
+
logger.debug("[warmup] tracking dependencies for %s failed with: %s", url, e);
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
await Promise.all(entries.map((entry) => warmup(fileToUrl(entry, server.config.root))));
|
|
1594
1366
|
}
|
|
1595
1367
|
|
|
1368
|
+
//#endregion
|
|
1369
|
+
//#region src/css.ts
|
|
1596
1370
|
function sortPlugins({ plugins, order }) {
|
|
1597
|
-
|
|
1598
|
-
|
|
1371
|
+
const names = Object.keys(plugins);
|
|
1372
|
+
return typeof order === "function" ? order(names) : order || names;
|
|
1599
1373
|
}
|
|
1600
1374
|
async function resolveCSSOptions(nuxt) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
return css;
|
|
1375
|
+
const css = { postcss: { plugins: [] } };
|
|
1376
|
+
const postcssOptions = nuxt.options.postcss;
|
|
1377
|
+
const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias });
|
|
1378
|
+
for (const pluginName of sortPlugins(postcssOptions)) {
|
|
1379
|
+
const pluginOptions = postcssOptions.plugins[pluginName];
|
|
1380
|
+
if (!pluginOptions) continue;
|
|
1381
|
+
let pluginFn;
|
|
1382
|
+
for (const parentURL of nuxt.options.modulesDir) {
|
|
1383
|
+
pluginFn = await jiti.import(pluginName, {
|
|
1384
|
+
parentURL: parentURL.replace(/\/node_modules\/?$/, ""),
|
|
1385
|
+
try: true,
|
|
1386
|
+
default: true
|
|
1387
|
+
});
|
|
1388
|
+
if (typeof pluginFn === "function") {
|
|
1389
|
+
css.postcss.plugins.push(pluginFn(pluginOptions));
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`);
|
|
1394
|
+
}
|
|
1395
|
+
return css;
|
|
1626
1396
|
}
|
|
1627
1397
|
|
|
1398
|
+
//#endregion
|
|
1399
|
+
//#region src/plugins/ssr-styles.ts
|
|
1628
1400
|
const SUPPORTED_FILES_RE = /\.(?:vue|(?:[cm]?j|t)sx?)$/;
|
|
1629
1401
|
const QUERY_RE = /\?.+$/;
|
|
1630
1402
|
function SSRStylesPlugin(nuxt) {
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
const idFilename = filename(id);
|
|
1849
|
-
let styleCtr = 0;
|
|
1850
|
-
const ids = clientCSSMap[id] || [];
|
|
1851
|
-
for (const file of ids) {
|
|
1852
|
-
if (emittedIds.has(file)) {
|
|
1853
|
-
continue;
|
|
1854
|
-
}
|
|
1855
|
-
const fileInline = file + "?inline&used";
|
|
1856
|
-
const resolved = await this.resolve(file) ?? await this.resolve(file, id);
|
|
1857
|
-
const res = await this.resolve(fileInline) ?? await this.resolve(fileInline, id);
|
|
1858
|
-
if (!resolved || !res) {
|
|
1859
|
-
if (!warnCache.has(file)) {
|
|
1860
|
-
warnCache.add(file);
|
|
1861
|
-
this.warn(`[nuxt] Cannot extract styles for \`${file}\`. Its styles will not be inlined when server-rendering.`);
|
|
1862
|
-
}
|
|
1863
|
-
continue;
|
|
1864
|
-
}
|
|
1865
|
-
emittedIds.add(file);
|
|
1866
|
-
const ref = this.emitFile({
|
|
1867
|
-
type: "chunk",
|
|
1868
|
-
name: `${idFilename}-styles-${++styleCtr}.mjs`,
|
|
1869
|
-
id: fileInline
|
|
1870
|
-
});
|
|
1871
|
-
idRefMap[relativeToSrcDir(file)] = ref;
|
|
1872
|
-
idMap.files.push(ref);
|
|
1873
|
-
}
|
|
1874
|
-
if (!SUPPORTED_FILES_RE.test(pathname)) {
|
|
1875
|
-
return;
|
|
1876
|
-
}
|
|
1877
|
-
for (const i of findStaticImports(code)) {
|
|
1878
|
-
if (!i.specifier.endsWith(".css") && parseQuery(i.specifier).type !== "style") {
|
|
1879
|
-
continue;
|
|
1880
|
-
}
|
|
1881
|
-
const resolved = await this.resolve(i.specifier, id);
|
|
1882
|
-
if (!resolved) {
|
|
1883
|
-
continue;
|
|
1884
|
-
}
|
|
1885
|
-
const resolvedIdInline = resolved.id + "?inline&used";
|
|
1886
|
-
if (!await this.resolve(resolvedIdInline)) {
|
|
1887
|
-
if (!warnCache.has(resolved.id)) {
|
|
1888
|
-
warnCache.add(resolved.id);
|
|
1889
|
-
this.warn(`[nuxt] Cannot extract styles for \`${i.specifier}\`. Its styles will not be inlined when server-rendering.`);
|
|
1890
|
-
}
|
|
1891
|
-
continue;
|
|
1892
|
-
}
|
|
1893
|
-
if (emittedIds.has(resolved.id)) {
|
|
1894
|
-
continue;
|
|
1895
|
-
}
|
|
1896
|
-
const ref = this.emitFile({
|
|
1897
|
-
type: "chunk",
|
|
1898
|
-
name: `${idFilename}-styles-${++styleCtr}.mjs`,
|
|
1899
|
-
id: resolvedIdInline
|
|
1900
|
-
});
|
|
1901
|
-
idRefMap[relativeToSrcDir(resolved.id)] = ref;
|
|
1902
|
-
idMap.files.push(ref);
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
};
|
|
1907
|
-
}
|
|
1908
|
-
};
|
|
1403
|
+
if (nuxt.options.dev) return;
|
|
1404
|
+
const chunksWithInlinedCSS = /* @__PURE__ */ new Set();
|
|
1405
|
+
const clientCSSMap = {};
|
|
1406
|
+
const nitro = useNitro();
|
|
1407
|
+
nuxt.hook("build:manifest", (manifest) => {
|
|
1408
|
+
const entryIds = /* @__PURE__ */ new Set();
|
|
1409
|
+
for (const id of chunksWithInlinedCSS) {
|
|
1410
|
+
const chunk = manifest[id];
|
|
1411
|
+
if (!chunk) continue;
|
|
1412
|
+
if (chunk.isEntry && chunk.src) entryIds.add(chunk.src);
|
|
1413
|
+
else chunk.css &&= [];
|
|
1414
|
+
}
|
|
1415
|
+
nitro.options.virtual["#internal/nuxt/entry-ids.mjs"] = () => `export default ${JSON.stringify(Array.from(entryIds))}`;
|
|
1416
|
+
nitro.options._config.virtual ||= {};
|
|
1417
|
+
nitro.options._config.virtual["#internal/nuxt/entry-ids.mjs"] = nitro.options.virtual["#internal/nuxt/entry-ids.mjs"];
|
|
1418
|
+
});
|
|
1419
|
+
const cssMap = {};
|
|
1420
|
+
const idRefMap = {};
|
|
1421
|
+
const options = {
|
|
1422
|
+
shouldInline: nuxt.options.features.inlineStyles,
|
|
1423
|
+
globalCSS: nuxt.options.css
|
|
1424
|
+
};
|
|
1425
|
+
const relativeCache = /* @__PURE__ */ new Map();
|
|
1426
|
+
const relativeToSrcDir = (path) => {
|
|
1427
|
+
let cached = relativeCache.get(path);
|
|
1428
|
+
if (cached === void 0) {
|
|
1429
|
+
cached = relative(nuxt.options.srcDir, path);
|
|
1430
|
+
relativeCache.set(path, cached);
|
|
1431
|
+
}
|
|
1432
|
+
return cached;
|
|
1433
|
+
};
|
|
1434
|
+
const warnCache = /* @__PURE__ */ new Set();
|
|
1435
|
+
const components = nuxt.apps.default.components || [];
|
|
1436
|
+
const islands = components.filter((component) => component.island || component.mode === "server" && !components.some((c) => c.pascalName === component.pascalName && c.mode === "client"));
|
|
1437
|
+
const islandPaths = new Set(islands.map((c) => c.filePath));
|
|
1438
|
+
let entry;
|
|
1439
|
+
return {
|
|
1440
|
+
name: "ssr-styles",
|
|
1441
|
+
configResolved(config) {
|
|
1442
|
+
if (!config.build.ssr || nuxt.options.experimental.viteEnvironmentApi) entry = resolveClientEntry(config);
|
|
1443
|
+
},
|
|
1444
|
+
applyToEnvironment(environment) {
|
|
1445
|
+
return {
|
|
1446
|
+
name: `nuxt:ssr-styles:${environment.name}`,
|
|
1447
|
+
enforce: "pre",
|
|
1448
|
+
resolveId: {
|
|
1449
|
+
order: "pre",
|
|
1450
|
+
filter: { id: { include: [
|
|
1451
|
+
/^#build\/css$/,
|
|
1452
|
+
/\.vue$/,
|
|
1453
|
+
IS_CSS_RE
|
|
1454
|
+
] } },
|
|
1455
|
+
async handler(id, importer, _options) {
|
|
1456
|
+
if (options.shouldInline === false || typeof options.shouldInline === "function" && !options.shouldInline(importer)) return;
|
|
1457
|
+
const res = await this.resolve(id, importer, {
|
|
1458
|
+
..._options,
|
|
1459
|
+
skipSelf: true
|
|
1460
|
+
});
|
|
1461
|
+
if (res) return {
|
|
1462
|
+
...res,
|
|
1463
|
+
moduleSideEffects: false
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
},
|
|
1467
|
+
generateBundle(outputOptions) {
|
|
1468
|
+
if (environment.name === "client") return;
|
|
1469
|
+
const emitted = {};
|
|
1470
|
+
for (const [file, { files, inBundle }] of Object.entries(cssMap)) {
|
|
1471
|
+
if (!files.length || !inBundle) continue;
|
|
1472
|
+
const fileName = filename$1(file);
|
|
1473
|
+
const baseDir = dirname(typeof outputOptions.assetFileNames === "string" ? outputOptions.assetFileNames : outputOptions.assetFileNames({
|
|
1474
|
+
type: "asset",
|
|
1475
|
+
name: `${fileName}-styles.mjs`,
|
|
1476
|
+
names: [`${fileName}-styles.mjs`],
|
|
1477
|
+
originalFileName: `${fileName}-styles.mjs`,
|
|
1478
|
+
originalFileNames: [`${fileName}-styles.mjs`],
|
|
1479
|
+
source: ""
|
|
1480
|
+
}));
|
|
1481
|
+
const cssImports = /* @__PURE__ */ new Set();
|
|
1482
|
+
const exportNames = /* @__PURE__ */ new Set();
|
|
1483
|
+
const importStatements = /* @__PURE__ */ new Set();
|
|
1484
|
+
let i = 0;
|
|
1485
|
+
for (const css of files) {
|
|
1486
|
+
const file$1 = this.getFileName(css);
|
|
1487
|
+
if (cssImports.has(file$1)) continue;
|
|
1488
|
+
cssImports.add(file$1);
|
|
1489
|
+
const name = `style_${i++}`;
|
|
1490
|
+
importStatements.add(genImport(`./${relative(baseDir, file$1)}`, name));
|
|
1491
|
+
exportNames.add(name);
|
|
1492
|
+
}
|
|
1493
|
+
emitted[file] = this.emitFile({
|
|
1494
|
+
type: "asset",
|
|
1495
|
+
name: `${fileName}-styles.mjs`,
|
|
1496
|
+
source: [...importStatements, `export default ${genArrayFromRaw([...exportNames])}`].join("\n")
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
for (const key in emitted) chunksWithInlinedCSS.add(key);
|
|
1500
|
+
this.emitFile({
|
|
1501
|
+
type: "asset",
|
|
1502
|
+
fileName: "styles.mjs",
|
|
1503
|
+
originalFileName: "styles.mjs",
|
|
1504
|
+
source: ["const interopDefault = r => r.default || r || []", `export default ${genObjectFromRawEntries(Object.entries(emitted).map(([key, value]) => [key, `() => import('./${this.getFileName(value)}').then(interopDefault)`]))}`].join("\n")
|
|
1505
|
+
});
|
|
1506
|
+
},
|
|
1507
|
+
renderChunk(_code, chunk) {
|
|
1508
|
+
const isEntry = chunk.facadeModuleId === entry;
|
|
1509
|
+
if (isEntry) clientCSSMap[chunk.facadeModuleId] ||= /* @__PURE__ */ new Set();
|
|
1510
|
+
for (const moduleId of [chunk.facadeModuleId, ...chunk.moduleIds].filter(Boolean)) {
|
|
1511
|
+
if (environment.name === "client") {
|
|
1512
|
+
const moduleMap = clientCSSMap[moduleId] ||= /* @__PURE__ */ new Set();
|
|
1513
|
+
if (isCSS(moduleId)) {
|
|
1514
|
+
if (isVue(moduleId)) {
|
|
1515
|
+
moduleMap.add(moduleId);
|
|
1516
|
+
const parent = moduleId.replace(/\?.+$/, "");
|
|
1517
|
+
(clientCSSMap[parent] ||= /* @__PURE__ */ new Set()).add(moduleId);
|
|
1518
|
+
}
|
|
1519
|
+
if (isEntry && chunk.facadeModuleId) (clientCSSMap[chunk.facadeModuleId] ||= /* @__PURE__ */ new Set()).add(moduleId);
|
|
1520
|
+
}
|
|
1521
|
+
continue;
|
|
1522
|
+
}
|
|
1523
|
+
const relativePath = relativeToSrcDir(moduleId);
|
|
1524
|
+
if (relativePath in cssMap) cssMap[relativePath].inBundle = cssMap[relativePath].inBundle ?? (isVue(moduleId) && !!relativePath || isEntry);
|
|
1525
|
+
}
|
|
1526
|
+
return null;
|
|
1527
|
+
},
|
|
1528
|
+
transform: {
|
|
1529
|
+
filter: { id: {
|
|
1530
|
+
include: environment.name === "client" ? /* @__PURE__ */ new RegExp("^" + escapeStringRegexp(entry) + "$") : void 0,
|
|
1531
|
+
exclude: environment.name === "client" ? [] : [/\?.*macro=/, /\?.*nuxt_component=/]
|
|
1532
|
+
} },
|
|
1533
|
+
async handler(code, id) {
|
|
1534
|
+
if (environment.name === "client") {
|
|
1535
|
+
if (id === entry && (options.shouldInline === true || typeof options.shouldInline === "function" && options.shouldInline(id))) {
|
|
1536
|
+
const idClientCSSMap = clientCSSMap[id] ||= /* @__PURE__ */ new Set();
|
|
1537
|
+
if (!options.globalCSS.length) return;
|
|
1538
|
+
const s = new MagicString(code);
|
|
1539
|
+
for (const file of options.globalCSS) {
|
|
1540
|
+
const resolved = await this.resolve(file) ?? await this.resolve(file, id);
|
|
1541
|
+
const res = await this.resolve(file + "?inline&used") ?? await this.resolve(file + "?inline&used", id);
|
|
1542
|
+
if (!resolved || !res) {
|
|
1543
|
+
if (!warnCache.has(file)) {
|
|
1544
|
+
warnCache.add(file);
|
|
1545
|
+
this.warn(`[nuxt] Cannot extract styles for \`${file}\`. Its styles will not be inlined when server-rendering.`);
|
|
1546
|
+
}
|
|
1547
|
+
s.prepend(`${genImport(file)}\n`);
|
|
1548
|
+
continue;
|
|
1549
|
+
}
|
|
1550
|
+
idClientCSSMap.add(resolved.id);
|
|
1551
|
+
}
|
|
1552
|
+
if (s.hasChanged()) return {
|
|
1553
|
+
code: s.toString(),
|
|
1554
|
+
map: s.generateMap({ hires: true })
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
1560
|
+
if (!(id in clientCSSMap) && !islandPaths.has(pathname)) return;
|
|
1561
|
+
const query = parseQuery(search);
|
|
1562
|
+
if (query.macro || query.nuxt_component) return;
|
|
1563
|
+
if (!islandPaths.has(pathname)) {
|
|
1564
|
+
if (options.shouldInline === false || typeof options.shouldInline === "function" && !options.shouldInline(id)) return;
|
|
1565
|
+
}
|
|
1566
|
+
const relativeId = relativeToSrcDir(id);
|
|
1567
|
+
const idMap = cssMap[relativeId] ||= { files: [] };
|
|
1568
|
+
const emittedIds = /* @__PURE__ */ new Set();
|
|
1569
|
+
const idFilename = filename$1(id);
|
|
1570
|
+
let styleCtr = 0;
|
|
1571
|
+
const ids = clientCSSMap[id] || [];
|
|
1572
|
+
for (const file of ids) {
|
|
1573
|
+
if (emittedIds.has(file)) continue;
|
|
1574
|
+
const fileInline = file + "?inline&used";
|
|
1575
|
+
const resolved = await this.resolve(file) ?? await this.resolve(file, id);
|
|
1576
|
+
const res = await this.resolve(fileInline) ?? await this.resolve(fileInline, id);
|
|
1577
|
+
if (!resolved || !res) {
|
|
1578
|
+
if (!warnCache.has(file)) {
|
|
1579
|
+
warnCache.add(file);
|
|
1580
|
+
this.warn(`[nuxt] Cannot extract styles for \`${file}\`. Its styles will not be inlined when server-rendering.`);
|
|
1581
|
+
}
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
emittedIds.add(file);
|
|
1585
|
+
const ref = this.emitFile({
|
|
1586
|
+
type: "chunk",
|
|
1587
|
+
name: `${idFilename}-styles-${++styleCtr}.mjs`,
|
|
1588
|
+
id: fileInline
|
|
1589
|
+
});
|
|
1590
|
+
idRefMap[relativeToSrcDir(file)] = ref;
|
|
1591
|
+
idMap.files.push(ref);
|
|
1592
|
+
}
|
|
1593
|
+
if (!SUPPORTED_FILES_RE.test(pathname)) return;
|
|
1594
|
+
for (const i of findStaticImports(code)) {
|
|
1595
|
+
if (!i.specifier.endsWith(".css") && parseQuery(i.specifier).type !== "style") continue;
|
|
1596
|
+
const resolved = await this.resolve(i.specifier, id);
|
|
1597
|
+
if (!resolved) continue;
|
|
1598
|
+
const resolvedIdInline = resolved.id + "?inline&used";
|
|
1599
|
+
if (!await this.resolve(resolvedIdInline)) {
|
|
1600
|
+
if (!warnCache.has(resolved.id)) {
|
|
1601
|
+
warnCache.add(resolved.id);
|
|
1602
|
+
this.warn(`[nuxt] Cannot extract styles for \`${i.specifier}\`. Its styles will not be inlined when server-rendering.`);
|
|
1603
|
+
}
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
if (emittedIds.has(resolved.id)) continue;
|
|
1607
|
+
const ref = this.emitFile({
|
|
1608
|
+
type: "chunk",
|
|
1609
|
+
name: `${idFilename}-styles-${++styleCtr}.mjs`,
|
|
1610
|
+
id: resolvedIdInline
|
|
1611
|
+
});
|
|
1612
|
+
idRefMap[relativeToSrcDir(resolved.id)] = ref;
|
|
1613
|
+
idMap.files.push(ref);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1909
1620
|
}
|
|
1910
|
-
function filename(name) {
|
|
1911
|
-
|
|
1621
|
+
function filename$1(name) {
|
|
1622
|
+
return filename(name.replace(QUERY_RE, ""));
|
|
1912
1623
|
}
|
|
1913
1624
|
|
|
1625
|
+
//#endregion
|
|
1626
|
+
//#region src/plugins/replace.ts
|
|
1914
1627
|
function ReplacePlugin() {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
} else {
|
|
1932
|
-
return replacePlugin({ ...replaceOptions, preventAssignment: true });
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1628
|
+
return {
|
|
1629
|
+
name: "nuxt:replace",
|
|
1630
|
+
enforce: "post",
|
|
1631
|
+
async applyToEnvironment(environment) {
|
|
1632
|
+
const config = environment.getTopLevelConfig();
|
|
1633
|
+
const replaceOptions = Object.create(null);
|
|
1634
|
+
for (const define of [config.define || {}, environment.config.define || {}]) for (const key in define) if (key.startsWith("import.meta.")) replaceOptions[key] = define[key];
|
|
1635
|
+
if (config.isProduction && vite.rolldownVersion) {
|
|
1636
|
+
const { replacePlugin: replacePlugin$1 } = await import("rolldown/plugins");
|
|
1637
|
+
return replacePlugin$1(replaceOptions, { preventAssignment: true });
|
|
1638
|
+
} else return replacePlugin({
|
|
1639
|
+
...replaceOptions,
|
|
1640
|
+
preventAssignment: true
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1936
1644
|
}
|
|
1937
1645
|
|
|
1646
|
+
//#endregion
|
|
1647
|
+
//#region src/plugins/layer-dep-optimize.ts
|
|
1938
1648
|
function LayerDepOptimizePlugin(nuxt) {
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
const importer = normalize(_importer);
|
|
1961
|
-
const layerIndex = dirs.findIndex((dir) => importer.startsWith(dir));
|
|
1962
|
-
if (layerIndex !== -1) {
|
|
1963
|
-
dirs.splice(layerIndex, 1);
|
|
1964
|
-
await this.resolve(source, join(nuxt.options.srcDir, "index.html"), { skipSelf: true }).catch(() => null);
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
}
|
|
1968
|
-
};
|
|
1969
|
-
}
|
|
1649
|
+
if (!nuxt.options.dev) return;
|
|
1650
|
+
const layerDirs = [];
|
|
1651
|
+
const delimitedRootDir = nuxt.options.rootDir + "/";
|
|
1652
|
+
for (const dirs of getLayerDirectories(nuxt)) if (dirs.app !== nuxt.options.srcDir && !dirs.app.startsWith(delimitedRootDir)) layerDirs.push(dirs.app);
|
|
1653
|
+
if (layerDirs.length > 0) {
|
|
1654
|
+
layerDirs.sort().reverse();
|
|
1655
|
+
const dirs = [...layerDirs];
|
|
1656
|
+
return {
|
|
1657
|
+
name: "nuxt:optimize-layer-deps",
|
|
1658
|
+
enforce: "pre",
|
|
1659
|
+
resolveId: { async handler(source, _importer) {
|
|
1660
|
+
if (!_importer) return;
|
|
1661
|
+
const importer = normalize(_importer);
|
|
1662
|
+
const layerIndex = dirs.findIndex((dir) => importer.startsWith(dir));
|
|
1663
|
+
if (layerIndex !== -1) {
|
|
1664
|
+
dirs.splice(layerIndex, 1);
|
|
1665
|
+
await this.resolve(source, join(nuxt.options.srcDir, "index.html"), { skipSelf: true }).catch(() => null);
|
|
1666
|
+
}
|
|
1667
|
+
} }
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1970
1670
|
}
|
|
1971
1671
|
|
|
1672
|
+
//#endregion
|
|
1673
|
+
//#region src/dirs.ts
|
|
1972
1674
|
let _distDir = dirname(fileURLToPath(import.meta.url));
|
|
1973
|
-
if (/(?:chunks|shared)$/.test(_distDir))
|
|
1974
|
-
_distDir = dirname(_distDir);
|
|
1975
|
-
}
|
|
1675
|
+
if (/(?:chunks|shared)$/.test(_distDir)) _distDir = dirname(_distDir);
|
|
1976
1676
|
const distDir = _distDir;
|
|
1977
1677
|
|
|
1678
|
+
//#endregion
|
|
1679
|
+
//#region src/plugins/environments.ts
|
|
1978
1680
|
function EnvironmentsPlugin(nuxt) {
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
config.build.rollupOptions.output.advancedChunks = void 0;
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
},
|
|
2036
|
-
applyToEnvironment(environment) {
|
|
2037
|
-
if (environment.name === "client") {
|
|
2038
|
-
return [
|
|
2039
|
-
...nuxt.options.experimental.clientNodeCompat ? [NodeCompatAliasPlugin()] : [],
|
|
2040
|
-
{
|
|
2041
|
-
name: "nuxt:client:aliases",
|
|
2042
|
-
enforce: "post",
|
|
2043
|
-
resolveId: {
|
|
2044
|
-
filter: {
|
|
2045
|
-
id: Object.keys(clientAliases).map((id) => new RegExp("^" + escapeStringRegexp(id) + "$"))
|
|
2046
|
-
},
|
|
2047
|
-
handler: (source) => clientAliases[source]
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
];
|
|
2051
|
-
} else if (environment.name === "ssr") ;
|
|
2052
|
-
return false;
|
|
2053
|
-
}
|
|
2054
|
-
};
|
|
1681
|
+
const fileNames = withoutLeadingSlash(join(nuxt.options.app.buildAssetsDir, "[hash].js"));
|
|
1682
|
+
const clientOutputDir = join(useNitro().options.output.publicDir, nuxt.options.app.buildAssetsDir);
|
|
1683
|
+
const clientAliases = {
|
|
1684
|
+
"nitro/runtime": join(nuxt.options.buildDir, "nitro.client.mjs"),
|
|
1685
|
+
"#internal/nitro": join(nuxt.options.buildDir, "nitro.client.mjs"),
|
|
1686
|
+
"nitropack/runtime": join(nuxt.options.buildDir, "nitro.client.mjs"),
|
|
1687
|
+
"#app-manifest": resolveModulePath("mocked-exports/empty", { from: import.meta.url })
|
|
1688
|
+
};
|
|
1689
|
+
let viteConfig;
|
|
1690
|
+
return {
|
|
1691
|
+
name: "nuxt:environments",
|
|
1692
|
+
enforce: "pre",
|
|
1693
|
+
config(config) {
|
|
1694
|
+
viteConfig = config;
|
|
1695
|
+
if (!nuxt.options.dev) return { base: "./" };
|
|
1696
|
+
},
|
|
1697
|
+
configEnvironment(name, config) {
|
|
1698
|
+
if (!nuxt.options.experimental.viteEnvironmentApi && viteConfig.ssr) {
|
|
1699
|
+
config.optimizeDeps ||= {};
|
|
1700
|
+
config.optimizeDeps.include = void 0;
|
|
1701
|
+
}
|
|
1702
|
+
if (name === "client") {
|
|
1703
|
+
const outputConfig = config.build?.rollupOptions?.output;
|
|
1704
|
+
return { build: { rollupOptions: { output: {
|
|
1705
|
+
chunkFileNames: outputConfig?.chunkFileNames ?? (nuxt.options.dev ? void 0 : fileNames),
|
|
1706
|
+
entryFileNames: outputConfig?.entryFileNames ?? (nuxt.options.dev ? "entry.js" : fileNames),
|
|
1707
|
+
sourcemapPathTransform: outputConfig?.sourcemapPathTransform ?? ((relativeSourcePath, sourcemapPath) => {
|
|
1708
|
+
if (!isAbsolute(relativeSourcePath)) return relative(clientOutputDir, resolve(dirname(sourcemapPath), relativeSourcePath));
|
|
1709
|
+
return relativeSourcePath;
|
|
1710
|
+
})
|
|
1711
|
+
} } } };
|
|
1712
|
+
}
|
|
1713
|
+
if (name === "ssr") {
|
|
1714
|
+
if (config.build?.rollupOptions?.output && !Array.isArray(config.build.rollupOptions.output)) {
|
|
1715
|
+
config.build.rollupOptions.output.manualChunks = void 0;
|
|
1716
|
+
if (vite.rolldownVersion) config.build.rollupOptions.output.advancedChunks = void 0;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
},
|
|
1720
|
+
applyToEnvironment(environment) {
|
|
1721
|
+
if (environment.name === "client") return [...nuxt.options.experimental.clientNodeCompat ? [NodeCompatAliasPlugin()] : [], {
|
|
1722
|
+
name: "nuxt:client:aliases",
|
|
1723
|
+
enforce: "post",
|
|
1724
|
+
resolveId: {
|
|
1725
|
+
filter: { id: Object.keys(clientAliases).map((id) => /* @__PURE__ */ new RegExp("^" + escapeStringRegexp(id) + "$")) },
|
|
1726
|
+
handler: (source) => clientAliases[source]
|
|
1727
|
+
}
|
|
1728
|
+
}];
|
|
1729
|
+
else if (environment.name === "ssr") {}
|
|
1730
|
+
return false;
|
|
1731
|
+
}
|
|
1732
|
+
};
|
|
2055
1733
|
}
|
|
2056
1734
|
function NodeCompatAliasPlugin() {
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
1735
|
+
const nodeCompatAlias = defineEnv({
|
|
1736
|
+
nodeCompat: true,
|
|
1737
|
+
resolve: true
|
|
1738
|
+
}).env.alias;
|
|
1739
|
+
return {
|
|
1740
|
+
name: "nuxt:client:node-compat-aliases",
|
|
1741
|
+
resolveId: {
|
|
1742
|
+
order: "pre",
|
|
1743
|
+
handler(source) {
|
|
1744
|
+
if (source in nodeCompatAlias) return nodeCompatAlias[source];
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
2069
1748
|
}
|
|
2070
1749
|
|
|
1750
|
+
//#endregion
|
|
1751
|
+
//#region src/plugins/client-manifest.ts
|
|
2071
1752
|
function ClientManifestPlugin(nuxt) {
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
await nuxt.callHook("build:manifest", manifest);
|
|
2127
|
-
const precomputed = precomputeDependencies(manifest);
|
|
2128
|
-
await writeFile(resolve(serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
2129
|
-
await writeFile(resolve(serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
2130
|
-
if (!nuxt.options.dev) {
|
|
2131
|
-
await rm(manifestFile, { force: true });
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
};
|
|
1753
|
+
let clientEntry;
|
|
1754
|
+
let key;
|
|
1755
|
+
let disableCssCodeSplit;
|
|
1756
|
+
return {
|
|
1757
|
+
name: "nuxt:client-manifest",
|
|
1758
|
+
applyToEnvironment: (environment) => environment.name === "ssr",
|
|
1759
|
+
configResolved(config) {
|
|
1760
|
+
clientEntry = resolveClientEntry(config);
|
|
1761
|
+
key = relative(config.root, clientEntry);
|
|
1762
|
+
disableCssCodeSplit = config.build?.cssCodeSplit === false;
|
|
1763
|
+
},
|
|
1764
|
+
async closeBundle() {
|
|
1765
|
+
const devClientManifest = {
|
|
1766
|
+
"@vite/client": {
|
|
1767
|
+
isEntry: true,
|
|
1768
|
+
file: "@vite/client",
|
|
1769
|
+
css: [],
|
|
1770
|
+
module: true,
|
|
1771
|
+
resourceType: "script"
|
|
1772
|
+
},
|
|
1773
|
+
...nuxt.options.features.noScripts === "all" ? {} : { [clientEntry]: {
|
|
1774
|
+
isEntry: true,
|
|
1775
|
+
file: clientEntry,
|
|
1776
|
+
module: true,
|
|
1777
|
+
resourceType: "script"
|
|
1778
|
+
} }
|
|
1779
|
+
};
|
|
1780
|
+
const clientDist = resolve(nuxt.options.buildDir, "dist/client");
|
|
1781
|
+
const serverDist = resolve(nuxt.options.buildDir, "dist/server");
|
|
1782
|
+
const manifestFile = resolve(clientDist, "manifest.json");
|
|
1783
|
+
const clientManifest = nuxt.options.dev ? devClientManifest : JSON.parse(readFileSync(manifestFile, "utf-8"));
|
|
1784
|
+
const manifestEntries = Object.values(clientManifest);
|
|
1785
|
+
const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(nuxt.options.app.buildAssetsDir));
|
|
1786
|
+
const BASE_RE = /* @__PURE__ */ new RegExp(`^${escapeStringRegexp(buildAssetsDir)}`);
|
|
1787
|
+
for (const entry of manifestEntries) {
|
|
1788
|
+
entry.file &&= entry.file.replace(BASE_RE, "");
|
|
1789
|
+
for (const item of ["css", "assets"]) entry[item] &&= entry[item].map((i) => i.replace(BASE_RE, ""));
|
|
1790
|
+
}
|
|
1791
|
+
await mkdir(serverDist, { recursive: true });
|
|
1792
|
+
if (disableCssCodeSplit) {
|
|
1793
|
+
for (const entry of manifestEntries) if (entry.file?.endsWith(".css")) {
|
|
1794
|
+
clientManifest[key].css ||= [];
|
|
1795
|
+
clientManifest[key].css.push(entry.file);
|
|
1796
|
+
break;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
const manifest = normalizeViteManifest(clientManifest);
|
|
1800
|
+
await nuxt.callHook("build:manifest", manifest);
|
|
1801
|
+
const precomputed = precomputeDependencies(manifest);
|
|
1802
|
+
await writeFile(resolve(serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
1803
|
+
await writeFile(resolve(serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
1804
|
+
if (!nuxt.options.dev) await rm(manifestFile, { force: true });
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
2135
1807
|
}
|
|
2136
1808
|
|
|
1809
|
+
//#endregion
|
|
1810
|
+
//#region src/plugins/resolve-deep-imports.ts
|
|
2137
1811
|
const VIRTUAL_RE = /^\0?virtual:(?:nuxt:)?/;
|
|
2138
1812
|
function ResolveDeepImportsPlugin(nuxt) {
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
});
|
|
2196
|
-
if (!path) {
|
|
2197
|
-
logger.debug("Could not resolve id", id, importer);
|
|
2198
|
-
return null;
|
|
2199
|
-
}
|
|
2200
|
-
return normalize(path);
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
};
|
|
1813
|
+
const exclude = [
|
|
1814
|
+
"virtual:",
|
|
1815
|
+
"\0virtual:",
|
|
1816
|
+
"/__skip_vite",
|
|
1817
|
+
"@vitest/"
|
|
1818
|
+
];
|
|
1819
|
+
const conditions = {};
|
|
1820
|
+
function resolveConditions(environment) {
|
|
1821
|
+
const resolvedConditions = new Set([nuxt.options.dev ? "development" : "production", ...environment.config.resolve.conditions]);
|
|
1822
|
+
if (resolvedConditions.has("browser")) {
|
|
1823
|
+
resolvedConditions.add("web");
|
|
1824
|
+
resolvedConditions.add("import");
|
|
1825
|
+
resolvedConditions.add("module");
|
|
1826
|
+
resolvedConditions.add("default");
|
|
1827
|
+
}
|
|
1828
|
+
if (environment.config.mode === "test") {
|
|
1829
|
+
resolvedConditions.add("import");
|
|
1830
|
+
resolvedConditions.add("require");
|
|
1831
|
+
}
|
|
1832
|
+
return [...resolvedConditions];
|
|
1833
|
+
}
|
|
1834
|
+
return {
|
|
1835
|
+
name: "nuxt:resolve-bare-imports",
|
|
1836
|
+
enforce: "post",
|
|
1837
|
+
resolveId: {
|
|
1838
|
+
filter: { id: { exclude: [/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i, ...exclude.map((e) => /* @__PURE__ */ new RegExp("^" + escapeStringRegexp(e)))] } },
|
|
1839
|
+
async handler(id, importer) {
|
|
1840
|
+
if (!importer || !isAbsolute(importer) && !VIRTUAL_RE.test(importer)) return;
|
|
1841
|
+
const normalisedId = resolveAlias(normalize(id), nuxt.options.alias);
|
|
1842
|
+
const isNuxtTemplate = importer.startsWith("virtual:nuxt");
|
|
1843
|
+
const normalisedImporter = (isNuxtTemplate ? decodeURIComponent(importer) : importer).replace(VIRTUAL_RE, "");
|
|
1844
|
+
if (nuxt.options.experimental.templateImportResolution !== false && isNuxtTemplate) {
|
|
1845
|
+
const template = nuxt.options.build.templates.find((t) => resolve(nuxt.options.buildDir, t.filename) === normalisedImporter);
|
|
1846
|
+
if (template?._path) {
|
|
1847
|
+
const res$1 = await this.resolve?.(normalisedId, template._path, { skipSelf: true });
|
|
1848
|
+
if (res$1 !== void 0 && res$1 !== null) return res$1;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
const dir = parseNodeModulePath(normalisedImporter).dir || nuxt.options.appDir;
|
|
1852
|
+
const res = await this.resolve?.(normalisedId, dir, { skipSelf: true });
|
|
1853
|
+
if (res !== void 0 && res !== null) return res;
|
|
1854
|
+
const environmentConditions = conditions[this.environment.name] ||= resolveConditions(this.environment);
|
|
1855
|
+
const path = resolveModulePath(id, {
|
|
1856
|
+
from: [dir, ...nuxt.options.modulesDir].map((d) => directoryToURL(d)),
|
|
1857
|
+
suffixes: ["", "index"],
|
|
1858
|
+
conditions: environmentConditions,
|
|
1859
|
+
try: true
|
|
1860
|
+
});
|
|
1861
|
+
if (!path) {
|
|
1862
|
+
logger.debug("Could not resolve id", id, importer);
|
|
1863
|
+
return null;
|
|
1864
|
+
}
|
|
1865
|
+
return normalize(path);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
2204
1869
|
}
|
|
2205
1870
|
|
|
1871
|
+
//#endregion
|
|
1872
|
+
//#region src/plugins/resolved-externals.ts
|
|
2206
1873
|
function ResolveExternalsPlugin(nuxt) {
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
try: true,
|
|
2250
|
-
from: importer,
|
|
2251
|
-
extensions: nuxt.options.extensions
|
|
2252
|
-
}) || res.id;
|
|
2253
|
-
}
|
|
2254
|
-
return {
|
|
2255
|
-
...res,
|
|
2256
|
-
external: "absolute"
|
|
2257
|
-
};
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
};
|
|
2262
|
-
}
|
|
2263
|
-
};
|
|
1874
|
+
let external = /* @__PURE__ */ new Set();
|
|
1875
|
+
const nitro = useNitro();
|
|
1876
|
+
return {
|
|
1877
|
+
name: "nuxt:resolve-externals",
|
|
1878
|
+
enforce: "pre",
|
|
1879
|
+
async config() {
|
|
1880
|
+
const { runtimeDependencies: runtimeNitroDependencies = [] } = await tryImportModule("nitropack/runtime/meta", { url: new URL(import.meta.url) }) || {};
|
|
1881
|
+
external = new Set([
|
|
1882
|
+
"unhead",
|
|
1883
|
+
"@unhead/vue",
|
|
1884
|
+
"@nuxt/devalue",
|
|
1885
|
+
"unstorage",
|
|
1886
|
+
...nitro.options.inlineDynamicImports ? ["vue", "@vue/server-renderer"] : [],
|
|
1887
|
+
...runtimeDependencies,
|
|
1888
|
+
...runtimeNitroDependencies
|
|
1889
|
+
]);
|
|
1890
|
+
return { optimizeDeps: { exclude: Array.from(external) } };
|
|
1891
|
+
},
|
|
1892
|
+
applyToEnvironment(environment) {
|
|
1893
|
+
if (nuxt.options.dev || environment.name !== "ssr") return false;
|
|
1894
|
+
return {
|
|
1895
|
+
name: "nuxt:resolve-externals:external",
|
|
1896
|
+
resolveId: {
|
|
1897
|
+
filter: { id: [...external].map((dep) => /* @__PURE__ */ new RegExp("^" + escapeStringRegexp(dep) + "$")) },
|
|
1898
|
+
async handler(id, importer) {
|
|
1899
|
+
const res = await this.resolve?.(id, importer, { skipSelf: true });
|
|
1900
|
+
if (res !== void 0 && res !== null) {
|
|
1901
|
+
if (res.id === id) res.id = resolveModulePath(res.id, {
|
|
1902
|
+
try: true,
|
|
1903
|
+
from: importer,
|
|
1904
|
+
extensions: nuxt.options.extensions
|
|
1905
|
+
}) || res.id;
|
|
1906
|
+
return {
|
|
1907
|
+
...res,
|
|
1908
|
+
external: "absolute"
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
2264
1916
|
}
|
|
2265
1917
|
|
|
1918
|
+
//#endregion
|
|
1919
|
+
//#region src/vite.ts
|
|
2266
1920
|
const bundle = async (nuxt) => {
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
ModulePreloadPolyfillPlugin(),
|
|
2428
|
-
// ensure changes in chunks do not invalidate whole build
|
|
2429
|
-
StableEntryPlugin(nuxt),
|
|
2430
|
-
AnalyzePlugin(nuxt)
|
|
2431
|
-
] : []
|
|
2432
|
-
],
|
|
2433
|
-
appType: "custom",
|
|
2434
|
-
server: {
|
|
2435
|
-
middlewareMode: true,
|
|
2436
|
-
watch: { ...nuxt.options.watchers.chokidar, ignored: [isIgnored, /[\\/]node_modules[\\/]/] },
|
|
2437
|
-
fs: {
|
|
2438
|
-
allow: [...new Set(allowDirs)]
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
},
|
|
2442
|
-
nuxt.options.experimental.viteEnvironmentApi ? {
|
|
2443
|
-
...viteConfig,
|
|
2444
|
-
environments: {
|
|
2445
|
-
ssr: $server,
|
|
2446
|
-
client: $client
|
|
2447
|
-
}
|
|
2448
|
-
} : viteConfig
|
|
2449
|
-
);
|
|
2450
|
-
if (!nuxt.options.dev) {
|
|
2451
|
-
config.server.watch = void 0;
|
|
2452
|
-
config.build.watch = void 0;
|
|
2453
|
-
}
|
|
2454
|
-
const ctx = { nuxt, entry, config };
|
|
2455
|
-
await nuxt.callHook("vite:extend", ctx);
|
|
2456
|
-
if (nuxt.options.experimental.viteEnvironmentApi) {
|
|
2457
|
-
await handleEnvironments(nuxt, config);
|
|
2458
|
-
} else {
|
|
2459
|
-
await handleSerialBuilds(nuxt, ctx);
|
|
2460
|
-
}
|
|
1921
|
+
const useAsyncEntry = nuxt.options.experimental.asyncEntry || nuxt.options.dev;
|
|
1922
|
+
const entry = await resolvePath(resolve(nuxt.options.appDir, useAsyncEntry ? "entry.async" : "entry"));
|
|
1923
|
+
nuxt.options.modulesDir.push(distDir);
|
|
1924
|
+
let allowDirs = [
|
|
1925
|
+
nuxt.options.appDir,
|
|
1926
|
+
nuxt.options.workspaceDir,
|
|
1927
|
+
...nuxt.options.modulesDir,
|
|
1928
|
+
...getLayerDirectories(nuxt).map((d) => d.root),
|
|
1929
|
+
...Object.values(nuxt.apps).flatMap((app) => [
|
|
1930
|
+
...app.components.map((c) => dirname(c.filePath)),
|
|
1931
|
+
...app.plugins.map((p) => dirname(p.src)),
|
|
1932
|
+
...app.middleware.map((m) => dirname(m.path)),
|
|
1933
|
+
...Object.values(app.layouts || {}).map((l) => dirname(l.file)),
|
|
1934
|
+
dirname(nuxt.apps.default.rootComponent),
|
|
1935
|
+
dirname(nuxt.apps.default.errorComponent)
|
|
1936
|
+
])
|
|
1937
|
+
].filter((d) => d && existsSync(d));
|
|
1938
|
+
for (const dir of allowDirs) allowDirs = allowDirs.filter((d) => !d.startsWith(dir) || d === dir);
|
|
1939
|
+
const { $client, $server, ...viteConfig } = nuxt.options.vite;
|
|
1940
|
+
if (vite.rolldownVersion) {
|
|
1941
|
+
if (viteConfig.esbuild) delete viteConfig.esbuild;
|
|
1942
|
+
if (viteConfig.optimizeDeps?.esbuildOptions) delete viteConfig.optimizeDeps.esbuildOptions;
|
|
1943
|
+
}
|
|
1944
|
+
const mockEmpty = resolveModulePath("mocked-exports/empty", { from: import.meta.url });
|
|
1945
|
+
const helper = nuxt.options.nitro.imports !== false ? "" : "globalThis.";
|
|
1946
|
+
const isIgnored = createIsIgnored(nuxt);
|
|
1947
|
+
const serverEntry = nuxt.options.ssr ? entry : await resolvePath(resolve(nuxt.options.appDir, "entry-spa"));
|
|
1948
|
+
const config = mergeConfig({
|
|
1949
|
+
base: nuxt.options.dev ? joinURL(nuxt.options.app.baseURL.replace(/^\.\//, "/") || "/", nuxt.options.app.buildAssetsDir) : void 0,
|
|
1950
|
+
logLevel: logLevelMap[nuxt.options.logLevel] ?? logLevelMap.info,
|
|
1951
|
+
experimental: { renderBuiltUrl: (filename$2, { type, hostType, ssr: ssr$1 }) => {
|
|
1952
|
+
if (hostType !== "js") return { relative: true };
|
|
1953
|
+
if (!ssr$1) {
|
|
1954
|
+
if (type === "asset") return { relative: true };
|
|
1955
|
+
return { runtime: `globalThis.__publicAssetsURL(${JSON.stringify(filename$2)})` };
|
|
1956
|
+
}
|
|
1957
|
+
if (type === "public") return { runtime: `${helper}__publicAssetsURL(${JSON.stringify(filename$2)})` };
|
|
1958
|
+
if (type === "asset") {
|
|
1959
|
+
const relativeFilename = filename$2.replace(withTrailingSlash(withoutLeadingSlash(nuxt.options.app.buildAssetsDir)), "");
|
|
1960
|
+
return { runtime: `${helper}__buildAssetsURL(${JSON.stringify(relativeFilename)})` };
|
|
1961
|
+
}
|
|
1962
|
+
} },
|
|
1963
|
+
...nuxt.options.experimental.viteEnvironmentApi ? {
|
|
1964
|
+
builder: { async buildApp(builder) {
|
|
1965
|
+
const environments = Object.values(builder.environments);
|
|
1966
|
+
for (const environment of environments) {
|
|
1967
|
+
logger.restoreAll();
|
|
1968
|
+
await builder.build(environment);
|
|
1969
|
+
logger.wrapAll();
|
|
1970
|
+
await nuxt.callHook("vite:compiled");
|
|
1971
|
+
}
|
|
1972
|
+
} },
|
|
1973
|
+
environments: {
|
|
1974
|
+
client: {
|
|
1975
|
+
consumer: "client",
|
|
1976
|
+
keepProcessEnv: false,
|
|
1977
|
+
dev: { warmup: [entry] },
|
|
1978
|
+
...clientEnvironment(nuxt, entry)
|
|
1979
|
+
},
|
|
1980
|
+
ssr: {
|
|
1981
|
+
consumer: "server",
|
|
1982
|
+
dev: { warmup: [serverEntry] },
|
|
1983
|
+
...ssrEnvironment(nuxt, serverEntry)
|
|
1984
|
+
}
|
|
1985
|
+
},
|
|
1986
|
+
ssr: ssr(nuxt)
|
|
1987
|
+
} : {},
|
|
1988
|
+
resolve: {
|
|
1989
|
+
alias: {
|
|
1990
|
+
[basename(nuxt.options.dir.assets)]: resolve(nuxt.options.srcDir, nuxt.options.dir.assets),
|
|
1991
|
+
...nuxt.options.alias,
|
|
1992
|
+
"#app": nuxt.options.appDir,
|
|
1993
|
+
"web-streams-polyfill/ponyfill/es2018": mockEmpty,
|
|
1994
|
+
"abort-controller": mockEmpty
|
|
1995
|
+
},
|
|
1996
|
+
dedupe: ["vue"]
|
|
1997
|
+
},
|
|
1998
|
+
css: await resolveCSSOptions(nuxt),
|
|
1999
|
+
define: {
|
|
2000
|
+
__NUXT_VERSION__: JSON.stringify(nuxt._version),
|
|
2001
|
+
__NUXT_ASYNC_CONTEXT__: nuxt.options.experimental.asyncContext
|
|
2002
|
+
},
|
|
2003
|
+
build: {
|
|
2004
|
+
copyPublicDir: false,
|
|
2005
|
+
rollupOptions: { output: {
|
|
2006
|
+
sourcemapIgnoreList: (relativeSourcePath) => {
|
|
2007
|
+
return relativeSourcePath.includes("node_modules") || relativeSourcePath.includes(nuxt.options.buildDir);
|
|
2008
|
+
},
|
|
2009
|
+
sanitizeFileName: sanitizeFilePath,
|
|
2010
|
+
assetFileNames: nuxt.options.dev ? void 0 : (chunk) => withoutLeadingSlash(join(nuxt.options.app.buildAssetsDir, `${sanitizeFilePath(filename(chunk.names[0]))}.[hash].[ext]`))
|
|
2011
|
+
} },
|
|
2012
|
+
watch: vite.rolldownVersion ? { exclude: [...nuxt.options.ignore, /[\\/]node_modules[\\/]/] } : {
|
|
2013
|
+
chokidar: {
|
|
2014
|
+
...nuxt.options.watchers.chokidar,
|
|
2015
|
+
ignored: [isIgnored, /[\\/]node_modules[\\/]/]
|
|
2016
|
+
},
|
|
2017
|
+
exclude: nuxt.options.ignore
|
|
2018
|
+
}
|
|
2019
|
+
},
|
|
2020
|
+
plugins: [
|
|
2021
|
+
ResolveDeepImportsPlugin(nuxt),
|
|
2022
|
+
ResolveExternalsPlugin(nuxt),
|
|
2023
|
+
...nuxt.options.experimental.viteEnvironmentApi ? [
|
|
2024
|
+
vuePlugin(viteConfig.vue),
|
|
2025
|
+
viteJsxPlugin(viteConfig.vueJsx),
|
|
2026
|
+
ViteNodePlugin(nuxt),
|
|
2027
|
+
ClientManifestPlugin(nuxt),
|
|
2028
|
+
DevServerPlugin(nuxt)
|
|
2029
|
+
] : [],
|
|
2030
|
+
PublicDirsPlugin({
|
|
2031
|
+
dev: nuxt.options.dev,
|
|
2032
|
+
baseURL: nuxt.options.app.baseURL
|
|
2033
|
+
}),
|
|
2034
|
+
ReplacePlugin(),
|
|
2035
|
+
LayerDepOptimizePlugin(nuxt),
|
|
2036
|
+
SSRStylesPlugin(nuxt),
|
|
2037
|
+
EnvironmentsPlugin(nuxt),
|
|
2038
|
+
...nuxt.options.experimental.viteEnvironmentApi ? [
|
|
2039
|
+
VitePluginCheckerPlugin(nuxt),
|
|
2040
|
+
VueFeatureFlagsPlugin(nuxt),
|
|
2041
|
+
SourcemapPreserverPlugin(nuxt),
|
|
2042
|
+
DevStyleSSRPlugin({
|
|
2043
|
+
srcDir: nuxt.options.srcDir,
|
|
2044
|
+
buildAssetsURL: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir)
|
|
2045
|
+
}),
|
|
2046
|
+
RuntimePathsPlugin(),
|
|
2047
|
+
TypeCheckPlugin(nuxt),
|
|
2048
|
+
ModulePreloadPolyfillPlugin(),
|
|
2049
|
+
StableEntryPlugin(nuxt),
|
|
2050
|
+
AnalyzePlugin(nuxt)
|
|
2051
|
+
] : []
|
|
2052
|
+
],
|
|
2053
|
+
appType: "custom",
|
|
2054
|
+
server: {
|
|
2055
|
+
middlewareMode: true,
|
|
2056
|
+
watch: {
|
|
2057
|
+
...nuxt.options.watchers.chokidar,
|
|
2058
|
+
ignored: [isIgnored, /[\\/]node_modules[\\/]/]
|
|
2059
|
+
},
|
|
2060
|
+
fs: { allow: [...new Set(allowDirs)] }
|
|
2061
|
+
}
|
|
2062
|
+
}, nuxt.options.experimental.viteEnvironmentApi ? {
|
|
2063
|
+
...viteConfig,
|
|
2064
|
+
environments: {
|
|
2065
|
+
ssr: $server,
|
|
2066
|
+
client: $client
|
|
2067
|
+
}
|
|
2068
|
+
} : viteConfig);
|
|
2069
|
+
if (!nuxt.options.dev) {
|
|
2070
|
+
config.server.watch = void 0;
|
|
2071
|
+
config.build.watch = void 0;
|
|
2072
|
+
}
|
|
2073
|
+
const ctx = {
|
|
2074
|
+
nuxt,
|
|
2075
|
+
entry,
|
|
2076
|
+
config
|
|
2077
|
+
};
|
|
2078
|
+
await nuxt.callHook("vite:extend", ctx);
|
|
2079
|
+
if (nuxt.options.experimental.viteEnvironmentApi) await handleEnvironments(nuxt, config);
|
|
2080
|
+
else await handleSerialBuilds(nuxt, ctx);
|
|
2461
2081
|
};
|
|
2462
2082
|
async function handleEnvironments(nuxt, config) {
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2083
|
+
config.customLogger = createViteLogger(config);
|
|
2084
|
+
config.configFile = false;
|
|
2085
|
+
for (const environment of ["client", "ssr"]) {
|
|
2086
|
+
const environments = { [environment]: config.environments[environment] };
|
|
2087
|
+
const strippedConfig = {
|
|
2088
|
+
...config,
|
|
2089
|
+
environments
|
|
2090
|
+
};
|
|
2091
|
+
const ctx = {
|
|
2092
|
+
isServer: environment === "ssr",
|
|
2093
|
+
isClient: environment === "client"
|
|
2094
|
+
};
|
|
2095
|
+
await nuxt.hooks.callHook("vite:extendConfig", strippedConfig, ctx);
|
|
2096
|
+
await nuxt.hooks.callHook("vite:configResolved", strippedConfig, ctx);
|
|
2097
|
+
}
|
|
2098
|
+
if (!nuxt.options.dev) {
|
|
2099
|
+
await (await createBuilder(config)).buildApp();
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
await withLogs(async () => {
|
|
2103
|
+
await (await createServer(config)).environments.ssr.pluginContainer.buildStart({});
|
|
2104
|
+
}, "Vite dev server built");
|
|
2105
|
+
await writeDevServer(nuxt);
|
|
2482
2106
|
}
|
|
2483
2107
|
async function handleSerialBuilds(nuxt, ctx) {
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
await withLogs(() => buildClient(nuxt, ctx), "Vite client built", nuxt.options.dev);
|
|
2493
|
-
await withLogs(() => buildServer(nuxt, ctx), "Vite server built", nuxt.options.dev);
|
|
2108
|
+
nuxt.hook("vite:serverCreated", (server, env) => {
|
|
2109
|
+
if (nuxt.options.vite.warmupEntry !== false) useNitro().hooks.hookOnce("compiled", () => {
|
|
2110
|
+
const start = Date.now();
|
|
2111
|
+
warmupViteServer(server, [ctx.entry], env.isServer).then(() => logger.info(`Vite ${env.isClient ? "client" : "server"} warmed up in ${Date.now() - start}ms`)).catch(logger.error);
|
|
2112
|
+
});
|
|
2113
|
+
});
|
|
2114
|
+
await withLogs(() => buildClient(nuxt, ctx), "Vite client built", nuxt.options.dev);
|
|
2115
|
+
await withLogs(() => buildServer(nuxt, ctx), "Vite server built", nuxt.options.dev);
|
|
2494
2116
|
}
|
|
2495
2117
|
async function withLogs(fn, message, enabled = true) {
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
const duration = performance.now() - start;
|
|
2502
|
-
logger.success(`${message} in ${Math.round(duration)}ms`);
|
|
2118
|
+
if (!enabled) return fn();
|
|
2119
|
+
const start = performance.now();
|
|
2120
|
+
await fn();
|
|
2121
|
+
const duration = performance.now() - start;
|
|
2122
|
+
logger.success(`${message} in ${Math.round(duration)}ms`);
|
|
2503
2123
|
}
|
|
2504
2124
|
|
|
2505
|
-
|
|
2125
|
+
//#endregion
|
|
2126
|
+
export { bundle };
|