@nuxt/rspack-builder 4.2.2 → 4.3.0
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/README.md +4 -2
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +1376 -1143
- package/dist/loaders/vue-module-identifier.mjs +16 -0
- package/package.json +27 -23
- package/dist/index.d.ts +0 -5
package/dist/index.mjs
CHANGED
|
@@ -1,193 +1,527 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import webpackDevMiddleware from
|
|
4
|
-
import webpackHotMiddleware from
|
|
5
|
-
import { defu } from
|
|
6
|
-
import { joinURL } from
|
|
7
|
-
import { logger, useNitro, useNuxt } from
|
|
8
|
-
import { createUnplugin } from
|
|
9
|
-
import MagicString from
|
|
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
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import pify from "pify";
|
|
3
|
+
import webpackDevMiddleware from "webpack-dev-middleware";
|
|
4
|
+
import webpackHotMiddleware from "webpack-hot-middleware";
|
|
5
|
+
import { defu } from "defu";
|
|
6
|
+
import { joinURL, parseURL, withTrailingSlash } from "ufo";
|
|
7
|
+
import { directoryToURL, logger, resolveAlias, useNitro, useNuxt } from "@nuxt/kit";
|
|
8
|
+
import { createUnplugin } from "unplugin";
|
|
9
|
+
import MagicString from "magic-string";
|
|
10
|
+
import { MiniCssExtractPlugin, TsCheckerPlugin, WebpackBarPlugin, builder, webpack } from "#builder";
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
import { basename, isAbsolute, join, normalize, relative, resolve } from "pathe";
|
|
14
|
+
import { genArrayFromRaw, genObjectFromRawEntries, genString } from "knitwork";
|
|
15
|
+
import { compileStyle, parse } from "@vue/compiler-sfc";
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import { Volume, createFsFromVolume } from "memfs";
|
|
18
|
+
import querystring from "node:querystring";
|
|
19
|
+
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
20
|
+
import { defineEnv } from "unenv";
|
|
21
|
+
import TimeFixPlugin from "time-fix-plugin";
|
|
22
|
+
import FriendlyErrorsWebpackPlugin from "@nuxt/friendly-errors-webpack-plugin";
|
|
23
|
+
import escapeRegExp from "escape-string-regexp";
|
|
24
|
+
import { isTest } from "std-env";
|
|
25
|
+
import { EsbuildPlugin } from "esbuild-loader";
|
|
26
|
+
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
|
|
27
|
+
import createResolver from "postcss-import-resolver";
|
|
28
|
+
import { createJiti } from "jiti";
|
|
29
|
+
import VueLoaderPlugin from "vue-loader/dist/pluginWebpack5.js";
|
|
30
|
+
import { resolveModulePath } from "exsolve";
|
|
31
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
32
|
+
import { normalizeWebpackManifest, precomputeDependencies } from "vue-bundle-renderer";
|
|
33
|
+
import { hash } from "ohash";
|
|
34
|
+
import { serialize } from "seroval";
|
|
35
|
+
import { parseNodeModulePath } from "mlly";
|
|
30
36
|
|
|
37
|
+
//#region ../webpack/src/plugins/dynamic-base.ts
|
|
31
38
|
const defaults = {
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
globalPublicPath: "__webpack_public_path__",
|
|
40
|
+
sourcemap: true
|
|
34
41
|
};
|
|
35
42
|
const ENTRY_RE = /import ["']#build\/css["'];/;
|
|
36
43
|
const DynamicBasePlugin = createUnplugin((options = {}) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
options = {
|
|
45
|
+
...defaults,
|
|
46
|
+
...options
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
name: "nuxt:dynamic-base-path",
|
|
50
|
+
enforce: "post",
|
|
51
|
+
transform: {
|
|
52
|
+
filter: {
|
|
53
|
+
id: { include: /entry/ },
|
|
54
|
+
code: { include: ENTRY_RE }
|
|
55
|
+
},
|
|
56
|
+
handler(code) {
|
|
57
|
+
const s = new MagicString(code);
|
|
58
|
+
s.prepend(`import { buildAssetsURL } from '#internal/nuxt/paths';\n${options.globalPublicPath} = buildAssetsURL();\n`);
|
|
59
|
+
return {
|
|
60
|
+
code: s.toString(),
|
|
61
|
+
map: options.sourcemap ? s.generateMap({ hires: true }) : void 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
58
66
|
});
|
|
59
67
|
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region ../webpack/src/plugins/chunk.ts
|
|
60
70
|
const pluginName = "ChunkErrorPlugin";
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
var ChunkErrorPlugin = class {
|
|
72
|
+
apply(compiler) {
|
|
73
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
74
|
+
compilation.hooks.runtimeRequirementInTree.for(webpack.RuntimeGlobals.ensureChunk).tap(pluginName, (chunk) => {
|
|
75
|
+
compilation.addRuntimeModule(chunk, new ChunkErrorRuntimeModule());
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var ChunkErrorRuntimeModule = class extends webpack.RuntimeModule {
|
|
81
|
+
constructor() {
|
|
82
|
+
super("chunk preload error handler", webpack.RuntimeModule.STAGE_ATTACH);
|
|
83
|
+
}
|
|
84
|
+
generate() {
|
|
85
|
+
const { ensureChunk } = webpack.RuntimeGlobals;
|
|
86
|
+
return `
|
|
87
|
+
if (typeof ${ensureChunk} !== "undefined") {
|
|
88
|
+
var _ensureChunk = ${ensureChunk};
|
|
89
|
+
${ensureChunk} = function (chunkId) {
|
|
90
|
+
return Promise.resolve(_ensureChunk(chunkId)).catch(function(error) {
|
|
91
|
+
var e = new Event('nuxt:preloadError', { cancelable: true });
|
|
92
|
+
e.payload = error;
|
|
93
|
+
window.dispatchEvent(e);
|
|
94
|
+
throw error;
|
|
71
95
|
});
|
|
72
96
|
};
|
|
73
|
-
};`;
|
|
74
|
-
apply(compiler) {
|
|
75
|
-
compiler.hooks.thisCompilation.tap(
|
|
76
|
-
pluginName,
|
|
77
|
-
(compilation) => compilation.mainTemplate.hooks.localVars.tap(
|
|
78
|
-
{ name: pluginName, stage: 1 },
|
|
79
|
-
(source) => source + this.script
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
97
|
}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../webpack/src/plugins/ssr-styles.ts
|
|
104
|
+
const CSS_URL_RE = /url\((['"]?)(\/[^)]+?)\1\)/g;
|
|
105
|
+
const isVueFile = (id) => /\.vue(?:\?|$)/.test(id);
|
|
106
|
+
const isCSSLike = (name) => /\.(?:css|scss|sass|less|styl(?:us)?|postcss|pcss)(?:\?|$)/.test(name);
|
|
107
|
+
function normalizePath(nuxt$1, id) {
|
|
108
|
+
if (!id) return null;
|
|
109
|
+
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
110
|
+
const rel = relative(nuxt$1.options.srcDir, pathname);
|
|
111
|
+
if (rel.startsWith("..")) return null;
|
|
112
|
+
return rel;
|
|
113
|
+
}
|
|
114
|
+
function resolveFilePath(id) {
|
|
115
|
+
if (!id) return null;
|
|
116
|
+
return parseURL(decodeURIComponent(pathToFileURL(id).href)).pathname || null;
|
|
117
|
+
}
|
|
118
|
+
function sanitizeStyleAssetName(rel) {
|
|
119
|
+
return rel.replace(/[\\/]/g, "_").replace(/\.{2,}/g, "_");
|
|
120
|
+
}
|
|
121
|
+
function normalizeCSSContent(css) {
|
|
122
|
+
return css.trim().replace(/(--[^:]+):\s*'([^']*)'/g, "$1:\"$2\"").replace(/:\s+/g, ":").replace(/\s*\{\s*/g, "{").replace(/;\s*\}/g, "}").replace(/\s*\}\s*/g, "}");
|
|
123
|
+
}
|
|
124
|
+
function extractVueStyles(filePath) {
|
|
125
|
+
try {
|
|
126
|
+
const { descriptor } = parse(readFileSync(filePath, "utf8"), { filename: filePath });
|
|
127
|
+
const styles = [];
|
|
128
|
+
const scopeId = createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
129
|
+
for (let i = 0; i < descriptor.styles.length; i++) {
|
|
130
|
+
const style$1 = descriptor.styles[i];
|
|
131
|
+
const result = compileStyle({
|
|
132
|
+
source: style$1.content,
|
|
133
|
+
filename: filePath,
|
|
134
|
+
id: `data-v-${scopeId}`,
|
|
135
|
+
scoped: style$1.scoped
|
|
136
|
+
});
|
|
137
|
+
if (!result.errors.length && result.code) styles.push(normalizeCSSContent(result.code));
|
|
138
|
+
}
|
|
139
|
+
return styles;
|
|
140
|
+
} catch {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
var SSRStylesPlugin = class {
|
|
145
|
+
nuxt;
|
|
146
|
+
clientCSSByIssuer = /* @__PURE__ */ new Map();
|
|
147
|
+
chunksWithInlinedCSS = /* @__PURE__ */ new Set();
|
|
148
|
+
globalCSSPaths = /* @__PURE__ */ new Set();
|
|
149
|
+
constructor(nuxt$1) {
|
|
150
|
+
this.nuxt = nuxt$1;
|
|
151
|
+
this.globalCSSPaths = this.resolveGlobalCSS();
|
|
152
|
+
nuxt$1.hook("build:manifest", (manifest) => {
|
|
153
|
+
for (const [id, chunk] of Object.entries(manifest)) {
|
|
154
|
+
if (chunk.isEntry && chunk.src) this.chunksWithInlinedCSS.add(chunk.src);
|
|
155
|
+
else if (this.chunksWithInlinedCSS.has(id)) chunk.css &&= [];
|
|
156
|
+
if (chunk.css?.length) chunk.css = chunk.css.filter((cssPath) => {
|
|
157
|
+
for (const globalPath of this.globalCSSPaths) if (cssPath.includes(globalPath.split("/").pop() || "")) return false;
|
|
158
|
+
return true;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
shouldInline(mod) {
|
|
164
|
+
const shouldInline = this.nuxt.options.features.inlineStyles;
|
|
165
|
+
if (typeof shouldInline === "boolean") return shouldInline;
|
|
166
|
+
return shouldInline(mod.identifier());
|
|
167
|
+
}
|
|
168
|
+
escapeTemplateLiteral(str) {
|
|
169
|
+
return str.replace(/[`\\$]/g, (m) => m === "$" ? "\\$" : `\\${m}`);
|
|
170
|
+
}
|
|
171
|
+
isBuildAsset(url) {
|
|
172
|
+
const buildDir = withTrailingSlash(this.nuxt.options.app.buildAssetsDir || "/_nuxt/");
|
|
173
|
+
return url.startsWith(buildDir);
|
|
174
|
+
}
|
|
175
|
+
isPublicAsset(url, nitro) {
|
|
176
|
+
const cleaned = url.replace(/[?#].*$/, "");
|
|
177
|
+
for (const dir of nitro.options.publicAssets) {
|
|
178
|
+
const base$1 = withTrailingSlash(dir.baseURL || "/");
|
|
179
|
+
if (!url.startsWith(base$1)) continue;
|
|
180
|
+
if (existsSync(cleaned.replace(base$1, withTrailingSlash(dir.dir)))) return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
rewriteStyle(css, nitro) {
|
|
185
|
+
let changed = false;
|
|
186
|
+
let needsPublicAsset = false;
|
|
187
|
+
let needsBuildAsset = false;
|
|
188
|
+
let lastIndex = 0;
|
|
189
|
+
let out = "`";
|
|
190
|
+
for (const match of css.matchAll(CSS_URL_RE)) {
|
|
191
|
+
const index = match.index ?? 0;
|
|
192
|
+
const before = css.slice(lastIndex, index);
|
|
193
|
+
if (before) out += this.escapeTemplateLiteral(before);
|
|
194
|
+
const full = match[0];
|
|
195
|
+
const rawUrl = match[2] || "";
|
|
196
|
+
const stripped = rawUrl.replace(/[?#].*$/, "");
|
|
197
|
+
if (this.isPublicAsset(stripped, nitro)) {
|
|
198
|
+
needsPublicAsset = true;
|
|
199
|
+
changed = true;
|
|
200
|
+
out += "${publicAssetsURL(" + JSON.stringify(rawUrl) + ")}";
|
|
201
|
+
} else if (this.isBuildAsset(stripped)) {
|
|
202
|
+
needsBuildAsset = true;
|
|
203
|
+
changed = true;
|
|
204
|
+
out += "${buildAssetsURL(" + JSON.stringify(rawUrl) + ")}";
|
|
205
|
+
} else out += this.escapeTemplateLiteral(full);
|
|
206
|
+
lastIndex = index + full.length;
|
|
207
|
+
}
|
|
208
|
+
const tail = css.slice(lastIndex);
|
|
209
|
+
if (tail) out += this.escapeTemplateLiteral(tail);
|
|
210
|
+
out += "`";
|
|
211
|
+
return {
|
|
212
|
+
code: changed ? out : JSON.stringify(css),
|
|
213
|
+
needsPublicAsset,
|
|
214
|
+
needsBuildAsset
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
resolveGlobalCSS() {
|
|
218
|
+
const req = createRequire(this.nuxt.options.rootDir);
|
|
219
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
220
|
+
const entries = this.nuxt.options.css || [];
|
|
221
|
+
for (const entry of entries) {
|
|
222
|
+
const src = typeof entry === "string" ? entry : entry?.src;
|
|
223
|
+
if (!src) continue;
|
|
224
|
+
const path = this.resolveCSSRequest(src, req);
|
|
225
|
+
if (path) resolved.add(path);
|
|
226
|
+
}
|
|
227
|
+
return resolved;
|
|
228
|
+
}
|
|
229
|
+
resolveCSSRequest(request, req) {
|
|
230
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
231
|
+
const resolved = resolveAlias(request, this.nuxt.options.alias);
|
|
232
|
+
if (isAbsolute(resolved)) candidates.add(resolved);
|
|
233
|
+
else candidates.add(resolve(this.nuxt.options.srcDir, resolved));
|
|
234
|
+
try {
|
|
235
|
+
candidates.add(req.resolve(request));
|
|
236
|
+
} catch {}
|
|
237
|
+
for (const candidate of candidates) {
|
|
238
|
+
const path = resolveFilePath(candidate);
|
|
239
|
+
if (path) return path;
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
normalizeResourcePath(resource) {
|
|
244
|
+
if (!resource) return null;
|
|
245
|
+
const withoutQuery = resource.split("?")[0];
|
|
246
|
+
return resolveFilePath(withoutQuery);
|
|
247
|
+
}
|
|
248
|
+
apply(compiler) {
|
|
249
|
+
if (this.nuxt.options.dev) return;
|
|
250
|
+
const isClient = compiler.options.name === "client";
|
|
251
|
+
const isServer = compiler.options.name === "server";
|
|
252
|
+
if (!isClient && !isServer) return;
|
|
253
|
+
compiler.hooks.thisCompilation.tap("SSRStylesPlugin", (compilation) => {
|
|
254
|
+
this.collectCSS(compilation);
|
|
255
|
+
if (isClient) this.removeGlobalCSSFromClient(compilation);
|
|
256
|
+
if (isServer) this.emitServerStyles(compilation);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
emitServerStyles(compilation) {
|
|
260
|
+
const { webpack: webpack$1 } = compilation.compiler;
|
|
261
|
+
const stage = webpack$1.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE;
|
|
262
|
+
compilation.hooks.processAssets.tap({
|
|
263
|
+
name: "SSRStylesPlugin",
|
|
264
|
+
stage
|
|
265
|
+
}, () => {
|
|
266
|
+
const nitro = useNitro();
|
|
267
|
+
const collected = new Map(this.clientCSSByIssuer);
|
|
268
|
+
const entryModules = /* @__PURE__ */ new Set();
|
|
269
|
+
for (const entrypoint of compilation.entrypoints.values()) {
|
|
270
|
+
const primaryChunk = typeof entrypoint.getEntrypointChunk === "function" ? entrypoint.getEntrypointChunk() : void 0;
|
|
271
|
+
const chunks = primaryChunk ? [primaryChunk] : entrypoint.chunks;
|
|
272
|
+
for (const chunk of chunks) for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) if ("resource" in mod && typeof mod.resource === "string") {
|
|
273
|
+
const resolved = resolveFilePath(mod.resource);
|
|
274
|
+
if (resolved) {
|
|
275
|
+
const rel = normalizePath(this.nuxt, resolved);
|
|
276
|
+
if (rel) entryModules.add(rel);
|
|
277
|
+
else entryModules.add(resolved);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
for (const module of compilation.modules) {
|
|
282
|
+
const resource = module.resource;
|
|
283
|
+
if (!resource || !isVueFile(resource)) continue;
|
|
284
|
+
const rel = normalizePath(this.nuxt, resource);
|
|
285
|
+
if (!rel) continue;
|
|
286
|
+
if (collected.has(rel)) continue;
|
|
287
|
+
const vueStyles = extractVueStyles(resolveFilePath(resource) || resource);
|
|
288
|
+
if (vueStyles.length) collected.set(rel, new Set(vueStyles));
|
|
289
|
+
}
|
|
290
|
+
const emitted = {};
|
|
291
|
+
const rawSource = webpack$1.sources.RawSource;
|
|
292
|
+
for (const [rel, cssSet] of collected.entries()) {
|
|
293
|
+
if (!cssSet.size) continue;
|
|
294
|
+
const transformed = Array.from(cssSet).map((style$1) => this.rewriteStyle(style$1, nitro));
|
|
295
|
+
const needsPublicAssets = transformed.some((t) => t.needsPublicAsset);
|
|
296
|
+
const needsBuildAssets = transformed.some((t) => t.needsBuildAsset);
|
|
297
|
+
const imports = [];
|
|
298
|
+
if (needsPublicAssets || needsBuildAssets) {
|
|
299
|
+
const names = [];
|
|
300
|
+
if (needsBuildAssets) names.push("buildAssetsURL");
|
|
301
|
+
if (needsPublicAssets) names.push("publicAssetsURL");
|
|
302
|
+
imports.push(`import { ${names.join(", ")} } from '#internal/nuxt/paths'`);
|
|
303
|
+
}
|
|
304
|
+
const moduleSource = [...imports, `export default ${genArrayFromRaw(transformed.map((t) => t.code))}`].filter(Boolean).join("\n");
|
|
305
|
+
const styleModuleName = `${sanitizeStyleAssetName(rel)}-styles.mjs`;
|
|
306
|
+
compilation.emitAsset(styleModuleName, new rawSource(moduleSource));
|
|
307
|
+
emitted[rel] = styleModuleName;
|
|
308
|
+
this.chunksWithInlinedCSS.add(rel);
|
|
309
|
+
}
|
|
310
|
+
const stylesSource = ["const interopDefault = r => r.default || r || []", `export default ${genObjectFromRawEntries(Object.entries(emitted).map(([key, value]) => [key, `() => import('./${value}').then(interopDefault)`]))}`].join("\n");
|
|
311
|
+
compilation.emitAsset("styles.mjs", new rawSource(stylesSource));
|
|
312
|
+
const entryIds = Array.from(this.chunksWithInlinedCSS).filter((id) => entryModules.has(id));
|
|
313
|
+
nitro.options.virtual["#internal/nuxt/entry-ids.mjs"] = () => `export default ${JSON.stringify(entryIds)}`;
|
|
314
|
+
nitro.options._config.virtual ||= {};
|
|
315
|
+
nitro.options._config.virtual["#internal/nuxt/entry-ids.mjs"] = nitro.options.virtual["#internal/nuxt/entry-ids.mjs"];
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
findIssuerPath(compilation, mod) {
|
|
319
|
+
let issuer = compilation.moduleGraph.getIssuer(mod);
|
|
320
|
+
while (issuer) {
|
|
321
|
+
if ("resource" in issuer && typeof issuer.resource === "string") return issuer.resource;
|
|
322
|
+
issuer = compilation.moduleGraph.getIssuer(issuer);
|
|
323
|
+
}
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
removeGlobalCSSFromClient(compilation) {
|
|
327
|
+
compilation.hooks.processAssets.tap({
|
|
328
|
+
name: "SSRStylesPlugin:RemoveGlobalCSS",
|
|
329
|
+
stage: 650
|
|
330
|
+
}, () => {
|
|
331
|
+
for (const chunk of compilation.chunks) if (chunk.name === "nuxt-global-css") {
|
|
332
|
+
const cssAssets = [];
|
|
333
|
+
for (const file of Array.from(chunk.files)) {
|
|
334
|
+
const filename = String(file);
|
|
335
|
+
if (isCSSLike(filename)) {
|
|
336
|
+
const source = compilation.getAsset(filename)?.source;
|
|
337
|
+
const content = source && typeof source.source === "function" ? source.source() : null;
|
|
338
|
+
const text = typeof content === "string" ? content : content instanceof Buffer ? content.toString("utf8") : "";
|
|
339
|
+
if (text) cssAssets.push(text);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (cssAssets.length > 0) for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
343
|
+
const issuerPath = this.findIssuerPath(compilation, mod) || ("resource" in mod && typeof mod.resource === "string" ? mod.resource : null);
|
|
344
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
345
|
+
if (!normalized) continue;
|
|
346
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
347
|
+
for (const css of cssAssets) set.add(normalizeCSSContent(css));
|
|
348
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
349
|
+
}
|
|
350
|
+
for (const file of Array.from(chunk.files)) {
|
|
351
|
+
const filename = String(file);
|
|
352
|
+
if (isCSSLike(filename)) {
|
|
353
|
+
compilation.deleteAsset(filename);
|
|
354
|
+
chunk.files.delete(file);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
collectCSS(compilation) {
|
|
361
|
+
const { webpack: webpack$1 } = compilation.compiler;
|
|
362
|
+
const stage = compilation.compiler.options.name === "server" ? webpack$1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS : webpack$1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER;
|
|
363
|
+
const chunkCSSMeta = /* @__PURE__ */ new Map();
|
|
364
|
+
compilation.hooks.processAssets.tap({
|
|
365
|
+
name: "SSRStylesPlugin",
|
|
366
|
+
stage
|
|
367
|
+
}, () => {
|
|
368
|
+
const cssAssetsByChunk = /* @__PURE__ */ new Map();
|
|
369
|
+
for (const chunk of compilation.chunks) {
|
|
370
|
+
const cssAssets = [];
|
|
371
|
+
const chunkCSSFiles = [];
|
|
372
|
+
for (const file of chunk.files) {
|
|
373
|
+
if (!isCSSLike(file)) continue;
|
|
374
|
+
chunkCSSFiles.push(file);
|
|
375
|
+
const source = compilation.getAsset(file)?.source;
|
|
376
|
+
const content = source && typeof source.source === "function" ? source.source() : null;
|
|
377
|
+
const text = typeof content === "string" ? content : content instanceof Buffer ? content.toString("utf8") : "";
|
|
378
|
+
if (text) cssAssets.push(text);
|
|
379
|
+
}
|
|
380
|
+
if (chunkCSSFiles.length) {
|
|
381
|
+
const chunkCSSModules = Array.from(compilation.chunkGraph.getChunkModulesIterable(chunk));
|
|
382
|
+
chunkCSSMeta.set(chunk, {
|
|
383
|
+
files: chunkCSSFiles,
|
|
384
|
+
modules: chunkCSSModules
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
if (cssAssets.length) cssAssetsByChunk.set(chunk, cssAssets);
|
|
388
|
+
}
|
|
389
|
+
for (const [chunk, cssAssets] of cssAssetsByChunk) for (const mod of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
390
|
+
if (!this.shouldInline(mod)) continue;
|
|
391
|
+
const issuerPath = this.findIssuerPath(compilation, mod) || ("resource" in mod && typeof mod.resource === "string" ? mod.resource : null);
|
|
392
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
393
|
+
if (!normalized) continue;
|
|
394
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
395
|
+
for (const css of cssAssets) set.add(normalizeCSSContent(css));
|
|
396
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
397
|
+
}
|
|
398
|
+
for (const mod of compilation.modules) {
|
|
399
|
+
if (!this.shouldInline(mod)) continue;
|
|
400
|
+
const issuerPath = this.findIssuerPath(compilation, mod);
|
|
401
|
+
const normalized = normalizePath(this.nuxt, issuerPath);
|
|
402
|
+
if (!normalized) continue;
|
|
403
|
+
const cssChunks = this.getModuleCSS(mod, compilation);
|
|
404
|
+
if (!cssChunks.length) continue;
|
|
405
|
+
const set = this.clientCSSByIssuer.get(normalized) || /* @__PURE__ */ new Set();
|
|
406
|
+
set.add(cssChunks.join("\n"));
|
|
407
|
+
this.clientCSSByIssuer.set(normalized, set);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
getModuleCSS(mod, _compilation) {
|
|
412
|
+
const cssModule = mod;
|
|
413
|
+
const cssChunks = [];
|
|
414
|
+
if (mod.type === "css/mini-extract" && Array.isArray(cssModule.content)) for (const part of cssModule.content) {
|
|
415
|
+
const css = part?.[1];
|
|
416
|
+
if (css && typeof css === "string") cssChunks.push(normalizeCSSContent(css));
|
|
417
|
+
}
|
|
418
|
+
return cssChunks;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
84
421
|
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region ../webpack/src/utils/mfs.ts
|
|
85
424
|
function createMFS() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return _fs;
|
|
425
|
+
const _fs = { ...createFsFromVolume(new Volume()) };
|
|
426
|
+
_fs.join = join;
|
|
427
|
+
_fs.exists = (p) => Promise.resolve(_fs.existsSync(p));
|
|
428
|
+
_fs.readFile = pify(_fs.readFile);
|
|
429
|
+
return _fs;
|
|
92
430
|
}
|
|
93
431
|
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region ../webpack/src/utils/index.ts
|
|
434
|
+
/** @since 3.9.0 */
|
|
94
435
|
function toArray(value) {
|
|
95
|
-
|
|
436
|
+
return Array.isArray(value) ? value : [value];
|
|
96
437
|
}
|
|
97
438
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region ../webpack/src/utils/config.ts
|
|
441
|
+
function createWebpackConfigContext(nuxt$1) {
|
|
442
|
+
return {
|
|
443
|
+
nuxt: nuxt$1,
|
|
444
|
+
options: nuxt$1.options,
|
|
445
|
+
userConfig: nuxt$1.options.webpack,
|
|
446
|
+
config: {},
|
|
447
|
+
name: "base",
|
|
448
|
+
isDev: nuxt$1.options.dev,
|
|
449
|
+
isServer: false,
|
|
450
|
+
isClient: false,
|
|
451
|
+
alias: {},
|
|
452
|
+
transpile: []
|
|
453
|
+
};
|
|
111
454
|
}
|
|
112
455
|
async function applyPresets(ctx, presets) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
await preset[0](ctx, preset[1]);
|
|
116
|
-
} else {
|
|
117
|
-
await preset(ctx);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
456
|
+
for (const preset of toArray(presets)) if (Array.isArray(preset)) await preset[0](ctx, preset[1]);
|
|
457
|
+
else await preset(ctx);
|
|
120
458
|
}
|
|
121
459
|
function fileName(ctx, key) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
logger.warn(`Notice: Please do not use ${hash[1]} in dev mode to prevent memory leak`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return fileName2;
|
|
460
|
+
let fileName$1 = ctx.userConfig.filenames[key];
|
|
461
|
+
if (typeof fileName$1 === "function") fileName$1 = fileName$1(ctx);
|
|
462
|
+
if (typeof fileName$1 === "string" && ctx.options.dev) {
|
|
463
|
+
const hash$1 = /\[(chunkhash|contenthash|hash)(?::\d+)?\]/.exec(fileName$1);
|
|
464
|
+
if (hash$1) logger.warn(`Notice: Please do not use ${hash$1[1]} in dev mode to prevent memory leak`);
|
|
465
|
+
}
|
|
466
|
+
return fileName$1;
|
|
133
467
|
}
|
|
134
468
|
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region ../webpack/src/presets/assets.ts
|
|
135
471
|
function assets(ctx) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
}]
|
|
166
|
-
}
|
|
167
|
-
);
|
|
472
|
+
ctx.config.module.rules.push({
|
|
473
|
+
test: /\.(png|jpe?g|gif|svg|webp)$/i,
|
|
474
|
+
use: [{
|
|
475
|
+
loader: "url-loader",
|
|
476
|
+
options: {
|
|
477
|
+
...ctx.userConfig.loaders.imgUrl,
|
|
478
|
+
name: fileName(ctx, "img")
|
|
479
|
+
}
|
|
480
|
+
}]
|
|
481
|
+
}, {
|
|
482
|
+
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
|
|
483
|
+
use: [{
|
|
484
|
+
loader: "url-loader",
|
|
485
|
+
options: {
|
|
486
|
+
...ctx.userConfig.loaders.fontUrl,
|
|
487
|
+
name: fileName(ctx, "font")
|
|
488
|
+
}
|
|
489
|
+
}]
|
|
490
|
+
}, {
|
|
491
|
+
test: /\.(webm|mp4|ogv)$/i,
|
|
492
|
+
use: [{
|
|
493
|
+
loader: "file-loader",
|
|
494
|
+
options: {
|
|
495
|
+
...ctx.userConfig.loaders.file,
|
|
496
|
+
name: fileName(ctx, "video")
|
|
497
|
+
}
|
|
498
|
+
}]
|
|
499
|
+
});
|
|
168
500
|
}
|
|
169
501
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
502
|
+
//#endregion
|
|
503
|
+
//#region ../webpack/src/plugins/warning-ignore.ts
|
|
504
|
+
var WarningIgnorePlugin = class {
|
|
505
|
+
filter;
|
|
506
|
+
constructor(filter) {
|
|
507
|
+
this.filter = filter;
|
|
508
|
+
}
|
|
509
|
+
apply(compiler) {
|
|
510
|
+
compiler.hooks.done.tap("warnfix-plugin", (stats) => {
|
|
511
|
+
stats.compilation.warnings = stats.compilation.warnings.filter(this.filter);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
};
|
|
181
515
|
|
|
516
|
+
//#endregion
|
|
517
|
+
//#region ../webpack/src/plugins/vue/util.ts
|
|
518
|
+
/**
|
|
519
|
+
* This file is based on Vue.js (MIT) webpack plugins
|
|
520
|
+
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/util.js
|
|
521
|
+
*/
|
|
182
522
|
const validate = (compiler) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
if (!compiler.options.externals) {
|
|
187
|
-
logger.info(
|
|
188
|
-
"It is recommended to externalize dependencies in the server build for better build performance."
|
|
189
|
-
);
|
|
190
|
-
}
|
|
523
|
+
if (compiler.options.target !== "node") logger.warn("webpack config `target` should be \"node\".");
|
|
524
|
+
if (!compiler.options.externals) logger.info("It is recommended to externalize dependencies in the server build for better build performance.");
|
|
191
525
|
};
|
|
192
526
|
const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/;
|
|
193
527
|
const isJS = (file) => isJSRegExp.test(file);
|
|
@@ -196,87 +530,66 @@ const isCSSRegExp = /\.css(?:\?[^.]+)?$/;
|
|
|
196
530
|
const isCSS = (file) => isCSSRegExp.test(file);
|
|
197
531
|
const isHotUpdate = (file) => file.includes("hot-update");
|
|
198
532
|
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region ../webpack/src/plugins/rollup-compat-dynamic-import.ts
|
|
199
535
|
const DYNAMIC_IMPORT_RE = /import\([^)]*\+\s*__webpack_require__[^+]*\)\.then/;
|
|
200
536
|
const DYNAMIC_IMPORT_REPLACE_RE = /import\([^)]*\+\s*(__webpack_require__[^+]*)\)\.then/g;
|
|
201
537
|
const HELPER_FILENAME = "_dynamic-import-helper.mjs";
|
|
202
|
-
const HELPER_IMPORT = `import { _rollupDynamicImport } from "./${HELPER_FILENAME}"
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
return transformed;
|
|
259
|
-
}
|
|
260
|
-
generateDynamicImportHelper(compilation) {
|
|
261
|
-
const chunkFiles = [];
|
|
262
|
-
for (const chunk of compilation.chunks) {
|
|
263
|
-
if (chunk.hasRuntime()) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
for (const filename of chunk.files) {
|
|
267
|
-
if (filename && isJS(filename)) {
|
|
268
|
-
chunkFiles.push(filename);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (chunkFiles.length === 0) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const helperContent = this.generateHelperContent(chunkFiles);
|
|
276
|
-
compilation.emitAsset(HELPER_FILENAME, new compilation.compiler.webpack.sources.RawSource(helperContent));
|
|
277
|
-
}
|
|
278
|
-
generateHelperContent(chunkFiles) {
|
|
279
|
-
return `
|
|
538
|
+
const HELPER_IMPORT = `import { _rollupDynamicImport } from "./${HELPER_FILENAME}";\n`;
|
|
539
|
+
/**
|
|
540
|
+
* Webpack plugin that generates rollup-compatible dynamic imports.
|
|
541
|
+
* This plugin uses webpack's native compilation hooks to override dynamic import generation
|
|
542
|
+
* and create rollup-compatible code directly during webpack's compilation process.
|
|
543
|
+
*/
|
|
544
|
+
var RollupCompatDynamicImportPlugin = class {
|
|
545
|
+
apply(compiler) {
|
|
546
|
+
compiler.hooks.compilation.tap("RollupCompatDynamicImportPlugin", (compilation) => {
|
|
547
|
+
compilation.hooks.processAssets.tapAsync({
|
|
548
|
+
name: "RollupCompatDynamicImportPlugin",
|
|
549
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
|
550
|
+
}, (assets$1, callback) => {
|
|
551
|
+
try {
|
|
552
|
+
const targetFiles = /* @__PURE__ */ new Set();
|
|
553
|
+
for (const chunk of compilation.chunks) if (chunk.canBeInitial() || chunk.hasRuntime()) for (const file of chunk.files || []) targetFiles.add(file);
|
|
554
|
+
for (const [filename, asset] of Object.entries(assets$1)) {
|
|
555
|
+
if (!isJS(filename)) continue;
|
|
556
|
+
if (!targetFiles.has(filename)) continue;
|
|
557
|
+
const source = asset.source();
|
|
558
|
+
const originalCode = typeof source === "string" ? source : source.toString();
|
|
559
|
+
if (!DYNAMIC_IMPORT_RE.test(originalCode)) continue;
|
|
560
|
+
const transformedCode = this.transformDynamicImports(originalCode);
|
|
561
|
+
if (transformedCode !== originalCode) assets$1[filename] = new compiler.webpack.sources.RawSource(transformedCode);
|
|
562
|
+
}
|
|
563
|
+
this.generateDynamicImportHelper(compilation);
|
|
564
|
+
callback();
|
|
565
|
+
} catch (error) {
|
|
566
|
+
callback(error);
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
transformDynamicImports(source) {
|
|
572
|
+
let transformed = source;
|
|
573
|
+
let needsHelperImport = false;
|
|
574
|
+
transformed = transformed.replace(DYNAMIC_IMPORT_REPLACE_RE, (match, filename) => {
|
|
575
|
+
needsHelperImport = true;
|
|
576
|
+
return `_rollupDynamicImport(${filename}).then`;
|
|
577
|
+
});
|
|
578
|
+
if (needsHelperImport && !transformed.includes(HELPER_IMPORT)) transformed = HELPER_IMPORT + transformed;
|
|
579
|
+
return transformed;
|
|
580
|
+
}
|
|
581
|
+
generateDynamicImportHelper(compilation) {
|
|
582
|
+
const chunkFiles = [];
|
|
583
|
+
for (const chunk of compilation.chunks) {
|
|
584
|
+
if (chunk.hasRuntime()) continue;
|
|
585
|
+
for (const filename of chunk.files) if (filename && isJS(filename)) chunkFiles.push(filename);
|
|
586
|
+
}
|
|
587
|
+
if (chunkFiles.length === 0) return;
|
|
588
|
+
const helperContent = this.generateHelperContent(chunkFiles);
|
|
589
|
+
compilation.emitAsset(HELPER_FILENAME, new compilation.compiler.webpack.sources.RawSource(helperContent));
|
|
590
|
+
}
|
|
591
|
+
generateHelperContent(chunkFiles) {
|
|
592
|
+
return `
|
|
280
593
|
// Rollup-compatible dynamic import helper generated by webpack
|
|
281
594
|
// This helper enables rollup to consume webpack chunks directly
|
|
282
595
|
|
|
@@ -293,1000 +606,920 @@ export function _rollupDynamicImport(chunkId) {
|
|
|
293
606
|
return chunk()
|
|
294
607
|
}
|
|
295
608
|
`;
|
|
296
|
-
|
|
297
|
-
}
|
|
609
|
+
}
|
|
610
|
+
};
|
|
298
611
|
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region ../webpack/src/presets/base.ts
|
|
299
614
|
async function base(ctx) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
615
|
+
await applyPresets(ctx, [
|
|
616
|
+
baseAlias,
|
|
617
|
+
baseConfig,
|
|
618
|
+
basePlugins,
|
|
619
|
+
baseResolve,
|
|
620
|
+
baseTranspile
|
|
621
|
+
]);
|
|
307
622
|
}
|
|
308
623
|
function baseConfig(ctx) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
...ctx.config
|
|
327
|
-
});
|
|
624
|
+
ctx.config = defu({}, {
|
|
625
|
+
name: ctx.name,
|
|
626
|
+
entry: { app: [resolve(ctx.options.appDir, ctx.options.experimental.asyncEntry ? "entry.async" : "entry")] },
|
|
627
|
+
module: { rules: [] },
|
|
628
|
+
plugins: [],
|
|
629
|
+
externals: [],
|
|
630
|
+
optimization: {
|
|
631
|
+
...ctx.userConfig.optimization,
|
|
632
|
+
minimizer: []
|
|
633
|
+
},
|
|
634
|
+
experiments: { ...ctx.userConfig.experiments },
|
|
635
|
+
mode: ctx.isDev ? "development" : "production",
|
|
636
|
+
cache: getCache(ctx),
|
|
637
|
+
output: getOutput(ctx),
|
|
638
|
+
stats: statsMap[ctx.nuxt.options.logLevel] ?? statsMap.info,
|
|
639
|
+
...ctx.config
|
|
640
|
+
});
|
|
328
641
|
}
|
|
329
642
|
function basePlugins(ctx) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
done: (_, { stats }) => {
|
|
371
|
-
if (stats.hasErrors()) {
|
|
372
|
-
ctx.nuxt.callHook(`${builder}:error`);
|
|
373
|
-
} else {
|
|
374
|
-
logger.success(`Finished building ${stats.compilation.name ?? "Nuxt app"}`);
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
allDone: () => {
|
|
378
|
-
ctx.nuxt.callHook(`${builder}:done`);
|
|
379
|
-
},
|
|
380
|
-
progress: ({ webpackbar }) => {
|
|
381
|
-
ctx.nuxt.callHook(`${builder}:progress`, webpackbar.statesArray);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}));
|
|
386
|
-
}
|
|
387
|
-
if (ctx.isServer && !ctx.isDev) {
|
|
388
|
-
ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
|
|
389
|
-
}
|
|
643
|
+
ctx.config.plugins ||= [];
|
|
644
|
+
if (ctx.options.dev) {
|
|
645
|
+
if (ctx.nuxt.options.builder !== "@nuxt/rspack-builder") ctx.config.plugins.push(new TimeFixPlugin());
|
|
646
|
+
}
|
|
647
|
+
ctx.config.plugins.push(...ctx.userConfig.plugins || []);
|
|
648
|
+
if (ctx.nuxt.options.builder !== "@nuxt/rspack-builder") ctx.config.plugins.push(new WarningIgnorePlugin(getWarningIgnoreFilter(ctx)));
|
|
649
|
+
ctx.config.plugins.push(new webpack.DefinePlugin(getEnv(ctx)));
|
|
650
|
+
if (ctx.isServer || ctx.isDev && ctx.userConfig.friendlyErrors) ctx.config.plugins.push(new FriendlyErrorsWebpackPlugin({
|
|
651
|
+
clearConsole: false,
|
|
652
|
+
reporter: "consola",
|
|
653
|
+
logLevel: "ERROR"
|
|
654
|
+
}));
|
|
655
|
+
if (ctx.nuxt.options.webpack.profile) ctx.config.plugins.push(new WebpackBarPlugin({
|
|
656
|
+
name: ctx.name,
|
|
657
|
+
color: {
|
|
658
|
+
client: "green",
|
|
659
|
+
server: "orange",
|
|
660
|
+
modern: "blue"
|
|
661
|
+
}[ctx.name],
|
|
662
|
+
reporters: ["stats"],
|
|
663
|
+
stats: !ctx.isDev,
|
|
664
|
+
reporter: { reporter: {
|
|
665
|
+
change: (_, { shortPath }) => {
|
|
666
|
+
if (!ctx.isServer) ctx.nuxt.callHook(`${builder}:change`, shortPath);
|
|
667
|
+
},
|
|
668
|
+
done: (_, { stats }) => {
|
|
669
|
+
if (stats.hasErrors()) ctx.nuxt.callHook(`${builder}:error`);
|
|
670
|
+
else logger.success(`Finished building ${stats.compilation.name ?? "Nuxt app"}`);
|
|
671
|
+
},
|
|
672
|
+
allDone: () => {
|
|
673
|
+
ctx.nuxt.callHook(`${builder}:done`);
|
|
674
|
+
},
|
|
675
|
+
progress: ({ webpackbar }) => {
|
|
676
|
+
ctx.nuxt.callHook(`${builder}:progress`, webpackbar.statesArray);
|
|
677
|
+
}
|
|
678
|
+
} }
|
|
679
|
+
}));
|
|
680
|
+
if (ctx.isServer && !ctx.isDev) ctx.config.plugins.push(new RollupCompatDynamicImportPlugin());
|
|
390
681
|
}
|
|
391
682
|
function baseAlias(ctx) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
683
|
+
ctx.alias = {
|
|
684
|
+
"#app": ctx.options.appDir,
|
|
685
|
+
[basename(ctx.nuxt.options.dir.assets)]: resolve(ctx.nuxt.options.srcDir, ctx.nuxt.options.dir.assets),
|
|
686
|
+
...ctx.options.alias,
|
|
687
|
+
...ctx.alias
|
|
688
|
+
};
|
|
689
|
+
if (ctx.isClient) {
|
|
690
|
+
ctx.alias["nitro/runtime"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
|
|
691
|
+
ctx.alias["#internal/nitro"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
|
|
692
|
+
ctx.alias["nitropack/runtime"] = resolve(ctx.nuxt.options.buildDir, "nitro.client.mjs");
|
|
693
|
+
}
|
|
403
694
|
}
|
|
404
695
|
function baseResolve(ctx) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
696
|
+
const webpackModulesDir = ["node_modules"].concat(ctx.options.modulesDir);
|
|
697
|
+
ctx.config.resolve = {
|
|
698
|
+
extensions: [
|
|
699
|
+
".wasm",
|
|
700
|
+
".mjs",
|
|
701
|
+
".js",
|
|
702
|
+
".ts",
|
|
703
|
+
".json",
|
|
704
|
+
".vue",
|
|
705
|
+
".jsx",
|
|
706
|
+
".tsx"
|
|
707
|
+
],
|
|
708
|
+
alias: ctx.alias,
|
|
709
|
+
modules: webpackModulesDir,
|
|
710
|
+
fullySpecified: false,
|
|
711
|
+
...ctx.config.resolve
|
|
712
|
+
};
|
|
713
|
+
ctx.config.resolveLoader = {
|
|
714
|
+
modules: webpackModulesDir,
|
|
715
|
+
...ctx.config.resolveLoader
|
|
716
|
+
};
|
|
417
717
|
}
|
|
418
718
|
function baseTranspile(ctx) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
|
|
435
|
-
} else if (pattern instanceof RegExp) {
|
|
436
|
-
transpile.push(pattern);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
ctx.transpile = [...transpile, ...ctx.transpile];
|
|
719
|
+
const transpile = [
|
|
720
|
+
/\.vue\.js/i,
|
|
721
|
+
/consola\/src/,
|
|
722
|
+
/vue-demi/,
|
|
723
|
+
/(^|\/)nuxt\/(src\/|dist\/)?(app|[^/]+\/runtime)($|\/)/
|
|
724
|
+
];
|
|
725
|
+
for (let pattern of ctx.options.build.transpile) {
|
|
726
|
+
if (typeof pattern === "function") {
|
|
727
|
+
const result = pattern(ctx);
|
|
728
|
+
if (result) pattern = result;
|
|
729
|
+
}
|
|
730
|
+
if (typeof pattern === "string") transpile.push(new RegExp(escapeRegExp(normalize(pattern))));
|
|
731
|
+
else if (pattern instanceof RegExp) transpile.push(pattern);
|
|
732
|
+
}
|
|
733
|
+
ctx.transpile = [...transpile, ...ctx.transpile];
|
|
440
734
|
}
|
|
441
735
|
function getCache(ctx) {
|
|
442
|
-
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
736
|
+
if (!ctx.options.dev) return false;
|
|
445
737
|
}
|
|
446
738
|
function getOutput(ctx) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
739
|
+
return {
|
|
740
|
+
path: resolve(ctx.options.buildDir, "dist", ctx.isServer ? "server" : joinURL("client", ctx.options.app.buildAssetsDir)),
|
|
741
|
+
filename: fileName(ctx, "app"),
|
|
742
|
+
chunkFilename: fileName(ctx, "chunk"),
|
|
743
|
+
publicPath: joinURL(ctx.options.app.baseURL, ctx.options.app.buildAssetsDir)
|
|
744
|
+
};
|
|
453
745
|
}
|
|
454
746
|
function getWarningIgnoreFilter(ctx) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
(warn) => warn.name === "ModuleDependencyWarning" && warn.message.includes("export 'default'") && warn.message.includes("nuxt_plugin_"),
|
|
458
|
-
...ctx.userConfig.warningIgnoreFilters || []
|
|
459
|
-
];
|
|
460
|
-
return (warn) => !filters.some((ignoreFilter) => ignoreFilter(warn));
|
|
747
|
+
const filters = [(warn) => warn.name === "ModuleDependencyWarning" && warn.message.includes("export 'default'") && warn.message.includes("nuxt_plugin_"), ...ctx.userConfig.warningIgnoreFilters || []];
|
|
748
|
+
return (warn) => !filters.some((ignoreFilter) => ignoreFilter(warn));
|
|
461
749
|
}
|
|
462
750
|
function getEnv(ctx) {
|
|
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
|
-
|
|
751
|
+
const _env = {
|
|
752
|
+
"process.env.NODE_ENV": JSON.stringify(ctx.config.mode),
|
|
753
|
+
"__NUXT_VERSION__": JSON.stringify(ctx.nuxt._version),
|
|
754
|
+
"__NUXT_ASYNC_CONTEXT__": ctx.options.experimental.asyncContext,
|
|
755
|
+
"process.env.VUE_ENV": JSON.stringify(ctx.name),
|
|
756
|
+
"process.dev": ctx.options.dev,
|
|
757
|
+
"process.test": isTest,
|
|
758
|
+
"process.browser": ctx.isClient,
|
|
759
|
+
"process.client": ctx.isClient,
|
|
760
|
+
"process.server": ctx.isServer,
|
|
761
|
+
"import.meta.dev": ctx.options.dev,
|
|
762
|
+
"import.meta.test": isTest,
|
|
763
|
+
"import.meta.browser": ctx.isClient,
|
|
764
|
+
"import.meta.client": ctx.isClient,
|
|
765
|
+
"import.meta.server": ctx.isServer
|
|
766
|
+
};
|
|
767
|
+
if (ctx.isClient) {
|
|
768
|
+
_env["process.prerender"] = false;
|
|
769
|
+
_env["process.nitro"] = false;
|
|
770
|
+
_env["import.meta.prerender"] = false;
|
|
771
|
+
_env["import.meta.nitro"] = false;
|
|
772
|
+
} else {
|
|
773
|
+
_env["process.prerender"] = "(()=>process.prerender)()";
|
|
774
|
+
_env["process.nitro"] = "(()=>process.nitro)()";
|
|
775
|
+
_env["import.meta.prerender"] = "(()=>import.meta.prerender)()";
|
|
776
|
+
_env["import.meta.nitro"] = "(()=>import.meta.nitro)()";
|
|
777
|
+
}
|
|
778
|
+
if (ctx.userConfig.aggressiveCodeRemoval) {
|
|
779
|
+
_env["typeof process"] = JSON.stringify(ctx.isServer ? "object" : "undefined");
|
|
780
|
+
_env["typeof window"] = _env["typeof document"] = JSON.stringify(!ctx.isServer ? "object" : "undefined");
|
|
781
|
+
}
|
|
782
|
+
return _env;
|
|
495
783
|
}
|
|
496
784
|
const statsMap = {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
785
|
+
silent: "none",
|
|
786
|
+
info: "normal",
|
|
787
|
+
verbose: "verbose"
|
|
500
788
|
};
|
|
501
789
|
|
|
790
|
+
//#endregion
|
|
791
|
+
//#region ../webpack/src/presets/esbuild.ts
|
|
502
792
|
function esbuild(ctx) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
options: {
|
|
529
|
-
target,
|
|
530
|
-
...ctx.nuxt.options.webpack.loaders.esbuild,
|
|
531
|
-
loader: "tsx"
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
);
|
|
793
|
+
const target = ctx.isServer ? "es2020" : "chrome85";
|
|
794
|
+
ctx.config.optimization.minimizer.push(new EsbuildPlugin());
|
|
795
|
+
ctx.config.module.rules.push({
|
|
796
|
+
test: /\.m?[jt]s$/i,
|
|
797
|
+
loader: "esbuild-loader",
|
|
798
|
+
exclude: (file) => {
|
|
799
|
+
const lastSegment = file.split("node_modules", 2)[1];
|
|
800
|
+
if (!lastSegment) return false;
|
|
801
|
+
return !ctx.transpile.some((module) => module.test(lastSegment));
|
|
802
|
+
},
|
|
803
|
+
resolve: { fullySpecified: false },
|
|
804
|
+
options: {
|
|
805
|
+
target,
|
|
806
|
+
...ctx.nuxt.options.webpack.loaders.esbuild,
|
|
807
|
+
loader: "ts"
|
|
808
|
+
}
|
|
809
|
+
}, {
|
|
810
|
+
test: /\.m?[jt]sx$/,
|
|
811
|
+
loader: "esbuild-loader",
|
|
812
|
+
options: {
|
|
813
|
+
target,
|
|
814
|
+
...ctx.nuxt.options.webpack.loaders.esbuild,
|
|
815
|
+
loader: "tsx"
|
|
816
|
+
}
|
|
817
|
+
});
|
|
535
818
|
}
|
|
536
819
|
|
|
820
|
+
//#endregion
|
|
821
|
+
//#region ../webpack/src/presets/pug.ts
|
|
537
822
|
function pug(ctx) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
{
|
|
552
|
-
loader: "pug-plain-loader",
|
|
553
|
-
options: ctx.userConfig.loaders.pugPlain
|
|
554
|
-
}
|
|
555
|
-
]
|
|
556
|
-
}
|
|
557
|
-
]
|
|
558
|
-
});
|
|
823
|
+
ctx.config.module.rules.push({
|
|
824
|
+
test: /\.pug$/i,
|
|
825
|
+
oneOf: [{
|
|
826
|
+
resourceQuery: /^\?vue/i,
|
|
827
|
+
use: [{
|
|
828
|
+
loader: "pug-plain-loader",
|
|
829
|
+
options: ctx.userConfig.loaders.pugPlain
|
|
830
|
+
}]
|
|
831
|
+
}, { use: ["raw-loader", {
|
|
832
|
+
loader: "pug-plain-loader",
|
|
833
|
+
options: ctx.userConfig.loaders.pugPlain
|
|
834
|
+
}] }]
|
|
835
|
+
});
|
|
559
836
|
}
|
|
560
837
|
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region ../webpack/src/utils/postcss.ts
|
|
561
840
|
const isPureObject = (obj) => obj !== null && !Array.isArray(obj) && typeof obj === "object";
|
|
562
841
|
function sortPlugins({ plugins, order }) {
|
|
563
|
-
|
|
564
|
-
|
|
842
|
+
const names = Object.keys(plugins);
|
|
843
|
+
return typeof order === "function" ? order(names) : order || names;
|
|
565
844
|
}
|
|
566
|
-
async function getPostcssConfig(nuxt) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
postcssOptions.plugins = plugins;
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
sourceMap: nuxt.options.webpack.cssSourceMap,
|
|
612
|
-
...nuxt.options.webpack.postcss,
|
|
613
|
-
postcssOptions
|
|
614
|
-
};
|
|
845
|
+
async function getPostcssConfig(nuxt$1) {
|
|
846
|
+
if (!nuxt$1.options.webpack.postcss || !nuxt$1.options.postcss) return false;
|
|
847
|
+
const postcssOptions = defu({}, nuxt$1.options.postcss, {
|
|
848
|
+
plugins: {
|
|
849
|
+
"postcss-import": { resolve: createResolver({
|
|
850
|
+
alias: { ...nuxt$1.options.alias },
|
|
851
|
+
modules: nuxt$1.options.modulesDir
|
|
852
|
+
}) },
|
|
853
|
+
"postcss-url": {}
|
|
854
|
+
},
|
|
855
|
+
sourceMap: nuxt$1.options.webpack.cssSourceMap
|
|
856
|
+
});
|
|
857
|
+
const jiti = createJiti(nuxt$1.options.rootDir, { alias: nuxt$1.options.alias });
|
|
858
|
+
if (!Array.isArray(postcssOptions.plugins) && isPureObject(postcssOptions.plugins)) {
|
|
859
|
+
const plugins = [];
|
|
860
|
+
for (const pluginName$1 of sortPlugins(postcssOptions)) {
|
|
861
|
+
const pluginOptions = postcssOptions.plugins[pluginName$1];
|
|
862
|
+
if (!pluginOptions) continue;
|
|
863
|
+
let pluginFn;
|
|
864
|
+
for (const parentURL of nuxt$1.options.modulesDir) {
|
|
865
|
+
pluginFn = await jiti.import(pluginName$1, {
|
|
866
|
+
parentURL: parentURL.replace(/\/node_modules\/?$/, ""),
|
|
867
|
+
try: true,
|
|
868
|
+
default: true
|
|
869
|
+
});
|
|
870
|
+
if (typeof pluginFn === "function") {
|
|
871
|
+
plugins.push(pluginFn(pluginOptions));
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (typeof pluginFn !== "function") console.warn(`[nuxt] could not import postcss plugin \`${pluginName$1}\`. Please report this as a bug.`);
|
|
876
|
+
}
|
|
877
|
+
postcssOptions.plugins = plugins;
|
|
878
|
+
}
|
|
879
|
+
return {
|
|
880
|
+
sourceMap: nuxt$1.options.webpack.cssSourceMap,
|
|
881
|
+
...nuxt$1.options.webpack.postcss,
|
|
882
|
+
postcssOptions
|
|
883
|
+
};
|
|
615
884
|
}
|
|
616
885
|
|
|
886
|
+
//#endregion
|
|
887
|
+
//#region ../webpack/src/presets/style.ts
|
|
617
888
|
async function style(ctx) {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
889
|
+
await applyPresets(ctx, [
|
|
890
|
+
loaders,
|
|
891
|
+
extractCSS,
|
|
892
|
+
minimizer
|
|
893
|
+
]);
|
|
623
894
|
}
|
|
624
895
|
function minimizer(ctx) {
|
|
625
|
-
|
|
626
|
-
ctx.config.optimization.minimizer.push(new CssMinimizerPlugin({
|
|
627
|
-
...ctx.userConfig.optimizeCSS
|
|
628
|
-
}));
|
|
629
|
-
}
|
|
896
|
+
if (ctx.userConfig.optimizeCSS && Array.isArray(ctx.config.optimization.minimizer)) ctx.config.optimization.minimizer.push(new CssMinimizerPlugin({ ...ctx.userConfig.optimizeCSS }));
|
|
630
897
|
}
|
|
631
898
|
function extractCSS(ctx) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
...config === true ? {} : config
|
|
641
|
-
}));
|
|
899
|
+
const config = ctx.userConfig.extractCSS;
|
|
900
|
+
if (!config) return;
|
|
901
|
+
const filename = fileName(ctx, "css");
|
|
902
|
+
ctx.config.plugins.push(new MiniCssExtractPlugin({
|
|
903
|
+
filename,
|
|
904
|
+
chunkFilename: filename,
|
|
905
|
+
...config === true ? {} : config
|
|
906
|
+
}));
|
|
642
907
|
}
|
|
643
908
|
async function loaders(ctx) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
909
|
+
ctx.config.module.rules.push(await createdStyleRule("css", /\.css$/i, null, ctx));
|
|
910
|
+
ctx.config.module.rules.push(await createdStyleRule("postcss", /\.p(ost)?css$/i, null, ctx));
|
|
911
|
+
const lessLoader = {
|
|
912
|
+
loader: "less-loader",
|
|
913
|
+
options: ctx.userConfig.loaders.less
|
|
914
|
+
};
|
|
915
|
+
ctx.config.module.rules.push(await createdStyleRule("less", /\.less$/i, lessLoader, ctx));
|
|
916
|
+
const sassLoader = {
|
|
917
|
+
loader: "sass-loader",
|
|
918
|
+
options: ctx.userConfig.loaders.sass
|
|
919
|
+
};
|
|
920
|
+
ctx.config.module.rules.push(await createdStyleRule("sass", /\.sass$/i, sassLoader, ctx));
|
|
921
|
+
const scssLoader = {
|
|
922
|
+
loader: "sass-loader",
|
|
923
|
+
options: ctx.userConfig.loaders.scss
|
|
924
|
+
};
|
|
925
|
+
ctx.config.module.rules.push(await createdStyleRule("scss", /\.scss$/i, scssLoader, ctx));
|
|
926
|
+
const stylusLoader = {
|
|
927
|
+
loader: "stylus-loader",
|
|
928
|
+
options: ctx.userConfig.loaders.stylus
|
|
929
|
+
};
|
|
930
|
+
ctx.config.module.rules.push(await createdStyleRule("stylus", /\.styl(us)?$/i, stylusLoader, ctx));
|
|
654
931
|
}
|
|
655
932
|
async function createdStyleRule(lang, test, processorLoader, ctx) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
// This matches <style module>
|
|
667
|
-
{
|
|
668
|
-
resourceQuery: /module/,
|
|
669
|
-
use: cssModuleLoaders.concat(styleLoaders)
|
|
670
|
-
},
|
|
671
|
-
// This matches plain <style> or <style scoped>
|
|
672
|
-
{
|
|
673
|
-
use: cssLoaders.concat(styleLoaders)
|
|
674
|
-
}
|
|
675
|
-
]
|
|
676
|
-
};
|
|
933
|
+
const styleLoaders = [await createPostcssLoadersRule(ctx), processorLoader].filter(Boolean);
|
|
934
|
+
ctx.userConfig.loaders.css.importLoaders = ctx.userConfig.loaders.cssModules.importLoaders = styleLoaders.length;
|
|
935
|
+
const cssLoaders = createCssLoadersRule(ctx, ctx.userConfig.loaders.css);
|
|
936
|
+
return {
|
|
937
|
+
test,
|
|
938
|
+
oneOf: [{
|
|
939
|
+
resourceQuery: /module/,
|
|
940
|
+
use: createCssLoadersRule(ctx, ctx.userConfig.loaders.cssModules).concat(styleLoaders)
|
|
941
|
+
}, { use: cssLoaders.concat(styleLoaders) }]
|
|
942
|
+
};
|
|
677
943
|
}
|
|
678
944
|
function createCssLoadersRule(ctx, cssLoaderOptions) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
cssLoader
|
|
692
|
-
];
|
|
693
|
-
}
|
|
694
|
-
return [
|
|
695
|
-
// https://github.com/vuejs/vue-style-loader/issues/56
|
|
696
|
-
// {
|
|
697
|
-
// loader: 'vue-style-loader',
|
|
698
|
-
// options: options.webpack.loaders.vueStyle
|
|
699
|
-
// },
|
|
700
|
-
cssLoader
|
|
701
|
-
];
|
|
945
|
+
const cssLoader = {
|
|
946
|
+
loader: "css-loader",
|
|
947
|
+
options: cssLoaderOptions
|
|
948
|
+
};
|
|
949
|
+
if (ctx.userConfig.extractCSS) {
|
|
950
|
+
if (ctx.isServer) {
|
|
951
|
+
if (cssLoader.options.modules) cssLoader.options.modules.exportOnlyLocals ??= true;
|
|
952
|
+
return [cssLoader];
|
|
953
|
+
}
|
|
954
|
+
return [{ loader: MiniCssExtractPlugin.loader }, cssLoader];
|
|
955
|
+
}
|
|
956
|
+
return [cssLoader];
|
|
702
957
|
}
|
|
703
958
|
async function createPostcssLoadersRule(ctx) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return {
|
|
712
|
-
loader: "postcss-loader",
|
|
713
|
-
options: config
|
|
714
|
-
};
|
|
959
|
+
if (!ctx.options.postcss) return;
|
|
960
|
+
const config = await getPostcssConfig(ctx.nuxt);
|
|
961
|
+
if (!config) return;
|
|
962
|
+
return {
|
|
963
|
+
loader: "postcss-loader",
|
|
964
|
+
options: config
|
|
965
|
+
};
|
|
715
966
|
}
|
|
716
967
|
|
|
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
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
for (const m2 of stats.modules) {
|
|
806
|
-
if (m2.assets?.length && m2.chunks?.includes(cid)) {
|
|
807
|
-
files.push(...m2.assets.map(fileToIndex));
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
813
|
-
await this.nuxt.callHook("build:manifest", manifest);
|
|
814
|
-
await mkdir(this.serverDist, { recursive: true });
|
|
815
|
-
const precomputed = precomputeDependencies(manifest);
|
|
816
|
-
await writeFile(join(this.serverDist, `client.manifest.json`), JSON.stringify(manifest, null, 2));
|
|
817
|
-
await writeFile(join(this.serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
818
|
-
await writeFile(join(this.serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
}
|
|
968
|
+
//#endregion
|
|
969
|
+
//#region ../webpack/src/plugins/vue/client.ts
|
|
970
|
+
/**
|
|
971
|
+
* This file is based on Vue.js (MIT) webpack plugins
|
|
972
|
+
* https://github.com/vuejs/vue/blob/dev/src/server/webpack-plugin/client.js
|
|
973
|
+
*/
|
|
974
|
+
var VueSSRClientPlugin = class {
|
|
975
|
+
serverDist;
|
|
976
|
+
nuxt;
|
|
977
|
+
constructor(options) {
|
|
978
|
+
this.serverDist = resolve(options.nuxt.options.buildDir, "dist/server");
|
|
979
|
+
this.nuxt = options.nuxt;
|
|
980
|
+
}
|
|
981
|
+
getRelativeModuleId(identifier, context) {
|
|
982
|
+
const id = identifier.replace(/\s\w+$/, "");
|
|
983
|
+
const resourceMatch = id.match(/([^!]*\.vue)(?:\?|$)/);
|
|
984
|
+
return resourceMatch && resourceMatch[1] ? normalize(relative(context, resourceMatch[1])).replace(/^\.\//, "").replace(/\\/g, "/") : id;
|
|
985
|
+
}
|
|
986
|
+
apply(compiler) {
|
|
987
|
+
compiler.hooks.afterEmit.tap("VueSSRClientPlugin", async (compilation) => {
|
|
988
|
+
const stats = compilation.getStats().toJson();
|
|
989
|
+
const context = this.nuxt.options.srcDir;
|
|
990
|
+
const initialFiles = /* @__PURE__ */ new Set();
|
|
991
|
+
for (const { assets: assets$1 } of Object.values(stats.entrypoints)) {
|
|
992
|
+
if (!assets$1) continue;
|
|
993
|
+
for (const asset of assets$1) {
|
|
994
|
+
const file = asset.name;
|
|
995
|
+
if ((isJS(file) || isCSS(file)) && !isHotUpdate(file)) initialFiles.add(file);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const allFiles = /* @__PURE__ */ new Set();
|
|
999
|
+
const asyncFiles = /* @__PURE__ */ new Set();
|
|
1000
|
+
const assetsMapping = {};
|
|
1001
|
+
for (const { name: file, chunkNames = [] } of stats.assets) {
|
|
1002
|
+
if (isHotUpdate(file)) continue;
|
|
1003
|
+
allFiles.add(file);
|
|
1004
|
+
const isFileJS = isJS(file);
|
|
1005
|
+
if (!initialFiles.has(file) && (isFileJS || isCSS(file))) asyncFiles.add(file);
|
|
1006
|
+
if (isFileJS) {
|
|
1007
|
+
const componentHash = hash(chunkNames.join("|"));
|
|
1008
|
+
(assetsMapping[componentHash] ||= []).push(file);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
const webpackManifest = {
|
|
1012
|
+
publicPath: stats.publicPath,
|
|
1013
|
+
all: [...allFiles],
|
|
1014
|
+
initial: [...initialFiles],
|
|
1015
|
+
async: [...asyncFiles],
|
|
1016
|
+
modules: {},
|
|
1017
|
+
assetsMapping
|
|
1018
|
+
};
|
|
1019
|
+
const { entrypoints = {}, namedChunkGroups = {} } = stats;
|
|
1020
|
+
const fileToIndex = (file) => webpackManifest.all.indexOf(String(file));
|
|
1021
|
+
for (const m of stats.modules) {
|
|
1022
|
+
if (m.chunks?.length !== 1) continue;
|
|
1023
|
+
const [cid] = m.chunks;
|
|
1024
|
+
const chunk = stats.chunks.find((c) => c.id === cid);
|
|
1025
|
+
if (!chunk || !chunk.files || !cid) continue;
|
|
1026
|
+
const relativeId = this.getRelativeModuleId(m.identifier, context);
|
|
1027
|
+
const filesSet = /* @__PURE__ */ new Set();
|
|
1028
|
+
for (const file of chunk.files) {
|
|
1029
|
+
const index = fileToIndex(file);
|
|
1030
|
+
if (index !== -1) filesSet.add(index);
|
|
1031
|
+
}
|
|
1032
|
+
for (const chunkName of chunk.names) if (!entrypoints[chunkName]) {
|
|
1033
|
+
const chunkGroup = namedChunkGroups[chunkName];
|
|
1034
|
+
if (chunkGroup) for (const asset of chunkGroup.assets) filesSet.add(fileToIndex(asset.name));
|
|
1035
|
+
}
|
|
1036
|
+
const files = Array.from(filesSet);
|
|
1037
|
+
webpackManifest.modules[relativeId] = files;
|
|
1038
|
+
if (Array.isArray(m.modules)) for (const concatenatedModule of m.modules) {
|
|
1039
|
+
const relativeId$1 = this.getRelativeModuleId(concatenatedModule.identifier, context);
|
|
1040
|
+
webpackManifest.modules[relativeId$1] ||= files;
|
|
1041
|
+
}
|
|
1042
|
+
if (stats.modules) {
|
|
1043
|
+
for (const m$1 of stats.modules) if (m$1.assets?.length && m$1.chunks?.includes(cid)) files.push(...m$1.assets.map(fileToIndex));
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
const manifest = normalizeWebpackManifest(webpackManifest);
|
|
1047
|
+
await this.nuxt.callHook("build:manifest", manifest);
|
|
1048
|
+
await mkdir(this.serverDist, { recursive: true });
|
|
1049
|
+
const precomputed = precomputeDependencies(manifest);
|
|
1050
|
+
await writeFile(join(this.serverDist, `client.manifest.json`), JSON.stringify(manifest, null, 2));
|
|
1051
|
+
await writeFile(join(this.serverDist, "client.manifest.mjs"), "export default " + serialize(manifest), "utf8");
|
|
1052
|
+
await writeFile(join(this.serverDist, "client.precomputed.mjs"), "export default " + serialize(precomputed), "utf8");
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
822
1056
|
|
|
1057
|
+
//#endregion
|
|
1058
|
+
//#region ../webpack/src/plugins/vue/server.ts
|
|
823
1059
|
const JS_MAP_RE = /\.js\.map$/;
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
} else {
|
|
872
|
-
delete assets[asset.name];
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
const src = JSON.stringify(bundle, null, 2);
|
|
876
|
-
assets[this.options.filename] = {
|
|
877
|
-
source: () => src,
|
|
878
|
-
size: () => src.length
|
|
879
|
-
};
|
|
880
|
-
const mjsSrc = "export default " + src;
|
|
881
|
-
assets[this.options.filename.replace(".json", ".mjs")] = {
|
|
882
|
-
source: () => mjsSrc,
|
|
883
|
-
map: () => null,
|
|
884
|
-
size: () => mjsSrc.length
|
|
885
|
-
};
|
|
886
|
-
cb();
|
|
887
|
-
});
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
}
|
|
1060
|
+
var VueSSRServerPlugin = class {
|
|
1061
|
+
options;
|
|
1062
|
+
constructor(options = {}) {
|
|
1063
|
+
this.options = Object.assign({ filename: null }, options);
|
|
1064
|
+
}
|
|
1065
|
+
apply(compiler) {
|
|
1066
|
+
validate(compiler);
|
|
1067
|
+
compiler.hooks.make.tap("VueSSRServerPlugin", (compilation) => {
|
|
1068
|
+
compilation.hooks.processAssets.tapAsync({
|
|
1069
|
+
name: "VueSSRServerPlugin",
|
|
1070
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
1071
|
+
}, (assets$1, cb) => {
|
|
1072
|
+
const stats = compilation.getStats().toJson();
|
|
1073
|
+
const [entryName] = Object.keys(stats.entrypoints);
|
|
1074
|
+
const entryInfo = stats.entrypoints[entryName];
|
|
1075
|
+
if (!entryInfo) return cb();
|
|
1076
|
+
const entryAssets = entryInfo.assets.filter((asset) => isJS(asset.name));
|
|
1077
|
+
if (entryAssets.length > 1) throw new Error("Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config.");
|
|
1078
|
+
const [entry] = entryAssets;
|
|
1079
|
+
if (!entry || typeof entry.name !== "string") throw new Error(`Entry "${entryName}" not found. Did you specify the correct entry option?`);
|
|
1080
|
+
const bundle$1 = {
|
|
1081
|
+
entry: entry.name,
|
|
1082
|
+
files: {},
|
|
1083
|
+
maps: {}
|
|
1084
|
+
};
|
|
1085
|
+
for (const asset of stats.assets) if (isJS(asset.name)) {
|
|
1086
|
+
const queryPart = extractQueryPartJS(asset.name);
|
|
1087
|
+
if (queryPart !== void 0) bundle$1.files[asset.name] = asset.name.replace(queryPart, "");
|
|
1088
|
+
else bundle$1.files[asset.name] = asset.name;
|
|
1089
|
+
} else if (JS_MAP_RE.test(asset.name)) bundle$1.maps[asset.name.replace(/\.map$/, "")] = asset.name;
|
|
1090
|
+
else delete assets$1[asset.name];
|
|
1091
|
+
const src = JSON.stringify(bundle$1, null, 2);
|
|
1092
|
+
assets$1[this.options.filename] = {
|
|
1093
|
+
source: () => src,
|
|
1094
|
+
size: () => src.length
|
|
1095
|
+
};
|
|
1096
|
+
const mjsSrc = "export default " + src;
|
|
1097
|
+
assets$1[this.options.filename.replace(".json", ".mjs")] = {
|
|
1098
|
+
source: () => mjsSrc,
|
|
1099
|
+
map: () => null,
|
|
1100
|
+
size: () => mjsSrc.length
|
|
1101
|
+
};
|
|
1102
|
+
cb();
|
|
1103
|
+
});
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
891
1107
|
|
|
1108
|
+
//#endregion
|
|
1109
|
+
//#region ../webpack/src/presets/vue.ts
|
|
892
1110
|
function vue(ctx) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1111
|
+
ctx.config.plugins.push(new (VueLoaderPlugin.default || VueLoaderPlugin)());
|
|
1112
|
+
ctx.config.module.rules.push({
|
|
1113
|
+
test: /\.vue$/i,
|
|
1114
|
+
loader: "vue-loader",
|
|
1115
|
+
options: {
|
|
1116
|
+
...ctx.userConfig.loaders.vue,
|
|
1117
|
+
isServerBuild: ctx.isServer
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
if (ctx.isClient) ctx.config.plugins.push(new VueSSRClientPlugin({ nuxt: ctx.nuxt }));
|
|
1121
|
+
else {
|
|
1122
|
+
ctx.config.plugins.push(new VueSSRServerPlugin({ filename: `${ctx.name}.manifest.json` }));
|
|
1123
|
+
const loaderPath = resolveModulePath("#vue-module-identifier", { from: import.meta.url });
|
|
1124
|
+
ctx.config.module.rules.push({
|
|
1125
|
+
test: /\.vue$/i,
|
|
1126
|
+
enforce: "post",
|
|
1127
|
+
use: [{
|
|
1128
|
+
loader: loaderPath,
|
|
1129
|
+
options: { srcDir: ctx.nuxt.options.srcDir }
|
|
1130
|
+
}]
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
ctx.config.plugins.push(new webpack.DefinePlugin({
|
|
1134
|
+
"__VUE_OPTIONS_API__": "true",
|
|
1135
|
+
"__VUE_PROD_DEVTOOLS__": "false",
|
|
1136
|
+
"__VUE_PROD_HYDRATION_MISMATCH_DETAILS__": ctx.nuxt.options.debug && ctx.nuxt.options.debug.hydration
|
|
1137
|
+
}));
|
|
911
1138
|
}
|
|
912
1139
|
|
|
1140
|
+
//#endregion
|
|
1141
|
+
//#region ../webpack/src/presets/nuxt.ts
|
|
913
1142
|
async function nuxt(ctx) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1143
|
+
await applyPresets(ctx, [
|
|
1144
|
+
base,
|
|
1145
|
+
assets,
|
|
1146
|
+
esbuild,
|
|
1147
|
+
pug,
|
|
1148
|
+
style,
|
|
1149
|
+
vue
|
|
1150
|
+
]);
|
|
922
1151
|
}
|
|
923
1152
|
|
|
1153
|
+
//#endregion
|
|
1154
|
+
//#region ../webpack/src/configs/client.ts
|
|
924
1155
|
async function client(ctx) {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1156
|
+
ctx.name = "client";
|
|
1157
|
+
ctx.isClient = true;
|
|
1158
|
+
await applyPresets(ctx, [
|
|
1159
|
+
nuxt,
|
|
1160
|
+
clientPlugins,
|
|
1161
|
+
clientOptimization,
|
|
1162
|
+
clientDevtool,
|
|
1163
|
+
clientPerformance,
|
|
1164
|
+
clientHMR,
|
|
1165
|
+
clientNodeCompat
|
|
1166
|
+
]);
|
|
936
1167
|
}
|
|
937
1168
|
function clientDevtool(ctx) {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
1169
|
+
if (!ctx.nuxt.options.sourcemap.client) {
|
|
1170
|
+
ctx.config.devtool = false;
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const prefix = ctx.nuxt.options.sourcemap.client === "hidden" ? "hidden-" : "";
|
|
1174
|
+
if (!ctx.isDev) {
|
|
1175
|
+
ctx.config.devtool = prefix + "source-map";
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
ctx.config.devtool = prefix + "eval-cheap-module-source-map";
|
|
948
1179
|
}
|
|
949
1180
|
function clientPerformance(ctx) {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1181
|
+
ctx.config.performance = {
|
|
1182
|
+
maxEntrypointSize: 1e3 * 1024,
|
|
1183
|
+
hints: ctx.isDev ? false : "warning",
|
|
1184
|
+
...ctx.config.performance
|
|
1185
|
+
};
|
|
955
1186
|
}
|
|
956
1187
|
function clientNodeCompat(ctx) {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
resource.request = resource.request.replace(/^node:/, "");
|
|
971
|
-
}));
|
|
1188
|
+
if (!ctx.nuxt.options.experimental.clientNodeCompat) return;
|
|
1189
|
+
ctx.config.plugins.push(new webpack.DefinePlugin({ global: "globalThis" }));
|
|
1190
|
+
ctx.config.resolve ||= {};
|
|
1191
|
+
ctx.config.resolve.fallback = {
|
|
1192
|
+
...defineEnv({
|
|
1193
|
+
nodeCompat: true,
|
|
1194
|
+
resolve: true
|
|
1195
|
+
}).env.alias,
|
|
1196
|
+
...ctx.config.resolve.fallback
|
|
1197
|
+
};
|
|
1198
|
+
ctx.config.plugins.unshift(new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
|
|
1199
|
+
resource.request = resource.request.replace(/^node:/, "");
|
|
1200
|
+
}));
|
|
972
1201
|
}
|
|
973
1202
|
function clientHMR(ctx) {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
app.unshift(
|
|
990
|
-
// https://github.com/webpack/webpack-hot-middleware#config
|
|
991
|
-
`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`
|
|
992
|
-
);
|
|
993
|
-
ctx.config.plugins ||= [];
|
|
994
|
-
ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
1203
|
+
if (!ctx.isDev) return;
|
|
1204
|
+
const clientOptions = ctx.userConfig.hotMiddleware?.client || {};
|
|
1205
|
+
const hotMiddlewareClientOptions = {
|
|
1206
|
+
reload: true,
|
|
1207
|
+
timeout: 3e4,
|
|
1208
|
+
path: joinURL(ctx.options.app.baseURL, "__webpack_hmr", ctx.name),
|
|
1209
|
+
...clientOptions,
|
|
1210
|
+
ansiColors: JSON.stringify(clientOptions.ansiColors || {}),
|
|
1211
|
+
overlayStyles: JSON.stringify(clientOptions.overlayStyles || {}),
|
|
1212
|
+
name: ctx.name
|
|
1213
|
+
};
|
|
1214
|
+
const hotMiddlewareClientOptionsStr = querystring.stringify(hotMiddlewareClientOptions);
|
|
1215
|
+
ctx.config.entry.app.unshift(`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`);
|
|
1216
|
+
ctx.config.plugins ||= [];
|
|
1217
|
+
ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
995
1218
|
}
|
|
996
|
-
function clientOptimization(
|
|
1219
|
+
function clientOptimization(ctx) {
|
|
1220
|
+
if (!ctx.nuxt.options.features.inlineStyles) return;
|
|
1221
|
+
const globalCSSPaths = /* @__PURE__ */ new Set();
|
|
1222
|
+
for (const css of ctx.options.css) if (typeof css === "string") {
|
|
1223
|
+
const resolved = resolveAlias(css, ctx.options.alias);
|
|
1224
|
+
globalCSSPaths.add(normalize(resolved));
|
|
1225
|
+
}
|
|
1226
|
+
if (globalCSSPaths.size > 0) {
|
|
1227
|
+
ctx.config.optimization ||= {};
|
|
1228
|
+
ctx.config.optimization.splitChunks ||= {};
|
|
1229
|
+
ctx.config.optimization.splitChunks.cacheGroups ||= {};
|
|
1230
|
+
ctx.config.optimization.splitChunks.cacheGroups.nuxtGlobalCSS = {
|
|
1231
|
+
name: "nuxt-global-css",
|
|
1232
|
+
chunks: "all",
|
|
1233
|
+
enforce: true,
|
|
1234
|
+
test: (module) => {
|
|
1235
|
+
if (module.type !== "css/mini-extract") return false;
|
|
1236
|
+
const identifier = normalize(module.identifier());
|
|
1237
|
+
for (const globalPath of globalCSSPaths) if (identifier.includes(globalPath)) return true;
|
|
1238
|
+
return false;
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
997
1242
|
}
|
|
998
1243
|
function clientPlugins(ctx) {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
logger
|
|
1015
|
-
}));
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1244
|
+
if (!ctx.isDev && !ctx.nuxt.options.test && ctx.name === "client" && ctx.userConfig.analyze && (ctx.userConfig.analyze === true || ctx.userConfig.analyze.enabled)) {
|
|
1245
|
+
const statsDir = resolve(ctx.options.analyzeDir);
|
|
1246
|
+
ctx.config.plugins.push(new BundleAnalyzerPlugin({
|
|
1247
|
+
analyzerMode: "static",
|
|
1248
|
+
defaultSizes: "gzip",
|
|
1249
|
+
generateStatsFile: true,
|
|
1250
|
+
openAnalyzer: true,
|
|
1251
|
+
reportFilename: resolve(statsDir, `${ctx.name}.html`),
|
|
1252
|
+
statsFilename: resolve(statsDir, `${ctx.name}.json`),
|
|
1253
|
+
...ctx.userConfig.analyze === true ? {} : ctx.userConfig.analyze
|
|
1254
|
+
}));
|
|
1255
|
+
}
|
|
1256
|
+
if (!ctx.nuxt.options.ssr) {
|
|
1257
|
+
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) ctx.config.plugins.push(new TsCheckerPlugin({ logger }));
|
|
1258
|
+
}
|
|
1018
1259
|
}
|
|
1019
1260
|
|
|
1261
|
+
//#endregion
|
|
1262
|
+
//#region ../webpack/src/presets/node.ts
|
|
1020
1263
|
function node(ctx) {
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
maxAssetSize: Number.POSITIVE_INFINITY
|
|
1048
|
-
};
|
|
1264
|
+
ctx.config.target = "node";
|
|
1265
|
+
ctx.config.node = false;
|
|
1266
|
+
ctx.config.experiments.outputModule = true;
|
|
1267
|
+
ctx.config.output = {
|
|
1268
|
+
...ctx.config.output,
|
|
1269
|
+
chunkFilename: "[name].mjs",
|
|
1270
|
+
chunkFormat: "module",
|
|
1271
|
+
chunkLoading: "import",
|
|
1272
|
+
module: true,
|
|
1273
|
+
environment: {
|
|
1274
|
+
module: true,
|
|
1275
|
+
arrowFunction: true,
|
|
1276
|
+
bigIntLiteral: true,
|
|
1277
|
+
const: true,
|
|
1278
|
+
destructuring: true,
|
|
1279
|
+
dynamicImport: true,
|
|
1280
|
+
forOf: true
|
|
1281
|
+
},
|
|
1282
|
+
library: { type: "module" }
|
|
1283
|
+
};
|
|
1284
|
+
ctx.config.performance = {
|
|
1285
|
+
...ctx.config.performance,
|
|
1286
|
+
hints: false,
|
|
1287
|
+
maxEntrypointSize: Number.POSITIVE_INFINITY,
|
|
1288
|
+
maxAssetSize: Number.POSITIVE_INFINITY
|
|
1289
|
+
};
|
|
1049
1290
|
}
|
|
1050
1291
|
|
|
1292
|
+
//#endregion
|
|
1293
|
+
//#region ../webpack/src/configs/server.ts
|
|
1051
1294
|
const assetPattern = /\.(?:css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(?:\?.*)?$/i;
|
|
1295
|
+
const VIRTUAL_RE = /^\0?virtual:(?:nuxt:)?/;
|
|
1052
1296
|
async function server(ctx) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1297
|
+
ctx.name = "server";
|
|
1298
|
+
ctx.isServer = true;
|
|
1299
|
+
await applyPresets(ctx, [
|
|
1300
|
+
nuxt,
|
|
1301
|
+
node,
|
|
1302
|
+
serverStandalone,
|
|
1303
|
+
serverPreset,
|
|
1304
|
+
serverPlugins
|
|
1305
|
+
]);
|
|
1062
1306
|
}
|
|
1063
1307
|
function serverPreset(ctx) {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
};
|
|
1308
|
+
ctx.config.output.filename = "server.mjs";
|
|
1309
|
+
if (ctx.nuxt.options.sourcemap.server) {
|
|
1310
|
+
const prefix = ctx.nuxt.options.sourcemap.server === "hidden" ? "hidden-" : "";
|
|
1311
|
+
ctx.config.devtool = prefix + (ctx.isDev ? "cheap-module-source-map" : "source-map");
|
|
1312
|
+
} else ctx.config.devtool = false;
|
|
1313
|
+
ctx.config.optimization = {
|
|
1314
|
+
splitChunks: false,
|
|
1315
|
+
minimize: false
|
|
1316
|
+
};
|
|
1317
|
+
if (ctx.isDev) ctx.config.output.asyncChunks = false;
|
|
1075
1318
|
}
|
|
1076
1319
|
function serverStandalone(ctx) {
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1320
|
+
const inline = [
|
|
1321
|
+
"src/",
|
|
1322
|
+
"#app",
|
|
1323
|
+
"nuxt",
|
|
1324
|
+
"nuxt3",
|
|
1325
|
+
"nuxt-nightly",
|
|
1326
|
+
"!",
|
|
1327
|
+
"-!",
|
|
1328
|
+
"~",
|
|
1329
|
+
"@/",
|
|
1330
|
+
"#",
|
|
1331
|
+
...ctx.options.build.transpile
|
|
1332
|
+
];
|
|
1333
|
+
const external = new Set([
|
|
1334
|
+
"nitro/runtime",
|
|
1335
|
+
"#internal/nitro",
|
|
1336
|
+
"nitropack/runtime",
|
|
1337
|
+
"#shared",
|
|
1338
|
+
resolve(ctx.nuxt.options.rootDir, ctx.nuxt.options.dir.shared),
|
|
1339
|
+
...ctx.nuxt["~runtimeDependencies"] || []
|
|
1340
|
+
]);
|
|
1341
|
+
if (!ctx.nuxt.options.dev) {
|
|
1342
|
+
external.add("#internal/nuxt/paths");
|
|
1343
|
+
external.add("#internal/nuxt/app-config");
|
|
1344
|
+
external.add("#app-manifest");
|
|
1345
|
+
}
|
|
1346
|
+
if (!Array.isArray(ctx.config.externals)) return;
|
|
1347
|
+
const conditions = [
|
|
1348
|
+
ctx.nuxt.options.dev ? "development" : "production",
|
|
1349
|
+
"node",
|
|
1350
|
+
"import",
|
|
1351
|
+
"require"
|
|
1352
|
+
];
|
|
1353
|
+
ctx.config.externals.push(({ request, context }, cb) => {
|
|
1354
|
+
if (!request) return cb(void 0, false);
|
|
1355
|
+
if (external.has(request)) {
|
|
1356
|
+
const resolved = resolveModulePath(request, {
|
|
1357
|
+
from: context ? [context, ...ctx.nuxt.options.modulesDir].map((d) => directoryToURL(d)) : ctx.nuxt.options.modulesDir.map((d) => directoryToURL(d)),
|
|
1358
|
+
suffixes: ["", "index"],
|
|
1359
|
+
conditions,
|
|
1360
|
+
try: true
|
|
1361
|
+
});
|
|
1362
|
+
if (resolved && isAbsolute(resolved)) return cb(void 0, resolved);
|
|
1363
|
+
return cb(void 0, true);
|
|
1364
|
+
}
|
|
1365
|
+
if (request[0] === "." || isAbsolute(request) || inline.find((prefix) => typeof prefix === "string" && request.startsWith(prefix)) || assetPattern.test(request)) return cb(void 0, false);
|
|
1366
|
+
if (context && request && !request.startsWith("node:") && (isAbsolute(context) || VIRTUAL_RE.test(context))) try {
|
|
1367
|
+
const resolved = resolveModulePath(resolveAlias(normalize(request), ctx.nuxt.options.alias), {
|
|
1368
|
+
from: [parseNodeModulePath(context).dir || ctx.nuxt.options.rootDir, ...ctx.nuxt.options.modulesDir].map((d) => directoryToURL(d)),
|
|
1369
|
+
suffixes: ["", "index"],
|
|
1370
|
+
conditions,
|
|
1371
|
+
try: true
|
|
1372
|
+
});
|
|
1373
|
+
if (resolved && isAbsolute(resolved)) return cb(void 0, false);
|
|
1374
|
+
} catch {}
|
|
1375
|
+
return cb(void 0, true);
|
|
1376
|
+
});
|
|
1118
1377
|
}
|
|
1119
1378
|
function serverPlugins(ctx) {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) {
|
|
1128
|
-
ctx.config.plugins.push(new TsCheckerPlugin({
|
|
1129
|
-
logger
|
|
1130
|
-
}));
|
|
1131
|
-
}
|
|
1379
|
+
ctx.config.plugins ||= [];
|
|
1380
|
+
if (ctx.userConfig.serverURLPolyfill) ctx.config.plugins.push(new webpack.ProvidePlugin({
|
|
1381
|
+
URL: [ctx.userConfig.serverURLPolyfill, "URL"],
|
|
1382
|
+
URLSearchParams: [ctx.userConfig.serverURLPolyfill, "URLSearchParams"]
|
|
1383
|
+
}));
|
|
1384
|
+
if (!ctx.nuxt.options.test && (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev)) ctx.config.plugins.push(new TsCheckerPlugin({ logger }));
|
|
1132
1385
|
}
|
|
1133
1386
|
|
|
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
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
await new Promise((resolve) => compiler?.close(resolve));
|
|
1172
|
-
}
|
|
1173
|
-
});
|
|
1174
|
-
if (nuxt.options.dev) {
|
|
1175
|
-
await Promise.all(compilers.map((c) => c && compile(c)));
|
|
1176
|
-
return;
|
|
1177
|
-
}
|
|
1178
|
-
for (const c of compilers) {
|
|
1179
|
-
if (c) {
|
|
1180
|
-
await compile(c);
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1387
|
+
//#endregion
|
|
1388
|
+
//#region ../webpack/src/webpack.ts
|
|
1389
|
+
const bundle = async (nuxt$1) => {
|
|
1390
|
+
const webpackConfigs = await Promise.all([client, ...nuxt$1.options.ssr ? [server] : []].map(async (preset) => {
|
|
1391
|
+
const ctx = createWebpackConfigContext(nuxt$1);
|
|
1392
|
+
ctx.userConfig = defu(nuxt$1.options.webpack[`$${preset.name}`], ctx.userConfig);
|
|
1393
|
+
await applyPresets(ctx, preset);
|
|
1394
|
+
return ctx.config;
|
|
1395
|
+
}));
|
|
1396
|
+
/** Remove Nitro rollup plugin for handling dynamic imports from webpack chunks */
|
|
1397
|
+
if (!nuxt$1.options.dev) useNitro().hooks.hook("rollup:before", (_nitro, config) => {
|
|
1398
|
+
const plugins = config.plugins;
|
|
1399
|
+
const existingPlugin = plugins.findIndex((i) => i && "name" in i && i.name === "dynamic-require");
|
|
1400
|
+
if (existingPlugin >= 0) plugins.splice(existingPlugin, 1);
|
|
1401
|
+
});
|
|
1402
|
+
await nuxt$1.callHook(`${builder}:config`, webpackConfigs);
|
|
1403
|
+
const mfs = nuxt$1.options.dev ? createMFS() : null;
|
|
1404
|
+
const ssrStylesPlugin = nuxt$1.options.ssr && !nuxt$1.options.dev && nuxt$1.options.features.inlineStyles ? new SSRStylesPlugin(nuxt$1) : null;
|
|
1405
|
+
for (const config of webpackConfigs) {
|
|
1406
|
+
config.plugins.push(DynamicBasePlugin.webpack({ sourcemap: !!nuxt$1.options.sourcemap[config.name] }));
|
|
1407
|
+
if (config.name === "client" && nuxt$1.options.experimental.emitRouteChunkError && nuxt$1.options.builder !== "@nuxt/rspack-builder") config.plugins.push(new ChunkErrorPlugin());
|
|
1408
|
+
if (ssrStylesPlugin) config.plugins.push(ssrStylesPlugin);
|
|
1409
|
+
}
|
|
1410
|
+
await nuxt$1.callHook(`${builder}:configResolved`, webpackConfigs);
|
|
1411
|
+
const compilers = webpackConfigs.map((config) => {
|
|
1412
|
+
const compiler = webpack(config);
|
|
1413
|
+
if (nuxt$1.options.dev && compiler) compiler.outputFileSystem = mfs;
|
|
1414
|
+
return compiler;
|
|
1415
|
+
});
|
|
1416
|
+
nuxt$1.hook("close", async () => {
|
|
1417
|
+
for (const compiler of compilers) await new Promise((resolve$1) => compiler.close(resolve$1));
|
|
1418
|
+
});
|
|
1419
|
+
if (nuxt$1.options.dev) {
|
|
1420
|
+
await Promise.all(compilers.map((c) => compile(c)));
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
for (const c of compilers) await compile(c);
|
|
1183
1424
|
};
|
|
1184
1425
|
async function createDevMiddleware(compiler) {
|
|
1185
|
-
|
|
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
|
-
return devMiddleware;
|
|
1426
|
+
const nuxt$1 = useNuxt();
|
|
1427
|
+
logger.debug("Creating webpack middleware...");
|
|
1428
|
+
const devMiddleware = webpackDevMiddleware(compiler, {
|
|
1429
|
+
publicPath: joinURL(nuxt$1.options.app.baseURL, nuxt$1.options.app.buildAssetsDir),
|
|
1430
|
+
outputFileSystem: compiler.outputFileSystem,
|
|
1431
|
+
stats: "none",
|
|
1432
|
+
...nuxt$1.options.webpack.devMiddleware
|
|
1433
|
+
});
|
|
1434
|
+
nuxt$1.hook("close", () => pify(devMiddleware.close.bind(devMiddleware))());
|
|
1435
|
+
const { client: _client, ...hotMiddlewareOptions } = nuxt$1.options.webpack.hotMiddleware || {};
|
|
1436
|
+
const hotMiddleware = webpackHotMiddleware(compiler, {
|
|
1437
|
+
log: false,
|
|
1438
|
+
heartbeat: 1e4,
|
|
1439
|
+
path: joinURL(nuxt$1.options.app.baseURL, "__webpack_hmr", compiler.options.name),
|
|
1440
|
+
...hotMiddlewareOptions
|
|
1441
|
+
});
|
|
1442
|
+
const devHandler = wdmToH3Handler(devMiddleware);
|
|
1443
|
+
await nuxt$1.callHook("server:devHandler", defineEventHandler(async (event) => {
|
|
1444
|
+
const body = await devHandler(event);
|
|
1445
|
+
if (body !== void 0) return body;
|
|
1446
|
+
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1447
|
+
await new Promise((resolve$1, reject) => hotMiddleware(req, res, (err) => err ? reject(err) : resolve$1()));
|
|
1448
|
+
}), { cors: () => true });
|
|
1449
|
+
return devMiddleware;
|
|
1211
1450
|
}
|
|
1212
|
-
function wdmToH3Handler(devMiddleware
|
|
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
|
-
devMiddleware(req, res, (err) => {
|
|
1238
|
-
if (err) {
|
|
1239
|
-
reject(err);
|
|
1240
|
-
} else {
|
|
1241
|
-
resolve(void 0);
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
});
|
|
1245
|
-
return body;
|
|
1246
|
-
});
|
|
1451
|
+
function wdmToH3Handler(devMiddleware) {
|
|
1452
|
+
return defineEventHandler(async (event) => {
|
|
1453
|
+
const { req, res } = "runtime" in event ? event.runtime.node : event.node;
|
|
1454
|
+
if (req.headers["sec-fetch-mode"] === "no-cors" && req.headers["sec-fetch-site"] === "cross-site") throw { status: 403 };
|
|
1455
|
+
event.context.webpack = {
|
|
1456
|
+
...event.context.webpack,
|
|
1457
|
+
devMiddleware: devMiddleware.context
|
|
1458
|
+
};
|
|
1459
|
+
return await new Promise((resolve$1, reject) => {
|
|
1460
|
+
res.stream = (stream) => {
|
|
1461
|
+
resolve$1(stream);
|
|
1462
|
+
};
|
|
1463
|
+
res.send = (data) => {
|
|
1464
|
+
resolve$1(data);
|
|
1465
|
+
};
|
|
1466
|
+
res.finish = (data) => {
|
|
1467
|
+
resolve$1(data);
|
|
1468
|
+
};
|
|
1469
|
+
devMiddleware(req, res, (err) => {
|
|
1470
|
+
if (err) reject(err);
|
|
1471
|
+
else resolve$1(void 0);
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
});
|
|
1247
1475
|
}
|
|
1248
1476
|
async function compile(compiler) {
|
|
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
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1477
|
+
const nuxt$1 = useNuxt();
|
|
1478
|
+
await nuxt$1.callHook(`${builder}:compile`, {
|
|
1479
|
+
name: compiler.options.name,
|
|
1480
|
+
compiler
|
|
1481
|
+
});
|
|
1482
|
+
compiler.hooks.done.tap("load-resources", async (stats$1) => {
|
|
1483
|
+
await nuxt$1.callHook(`${builder}:compiled`, {
|
|
1484
|
+
name: compiler.options.name,
|
|
1485
|
+
compiler,
|
|
1486
|
+
stats: stats$1
|
|
1487
|
+
});
|
|
1488
|
+
});
|
|
1489
|
+
if (nuxt$1.options.dev) {
|
|
1490
|
+
const compilersWatching = [];
|
|
1491
|
+
nuxt$1.hook("close", async () => {
|
|
1492
|
+
await Promise.all(compilersWatching.map((watching) => watching && pify(watching.close.bind(watching))()));
|
|
1493
|
+
});
|
|
1494
|
+
if (compiler.options.name === "client") return new Promise((resolve$1, reject) => {
|
|
1495
|
+
compiler.hooks.done.tap("nuxt-dev", () => {
|
|
1496
|
+
resolve$1(null);
|
|
1497
|
+
});
|
|
1498
|
+
compiler.hooks.failed.tap("nuxt-errorlog", (err) => {
|
|
1499
|
+
reject(err);
|
|
1500
|
+
});
|
|
1501
|
+
createDevMiddleware(compiler).then((devMiddleware) => {
|
|
1502
|
+
if (devMiddleware.context.watching) compilersWatching.push(devMiddleware.context.watching);
|
|
1503
|
+
});
|
|
1504
|
+
});
|
|
1505
|
+
return new Promise((resolve$1, reject) => {
|
|
1506
|
+
const watching = compiler.watch(nuxt$1.options.watchers.webpack, (err) => {
|
|
1507
|
+
if (err) return reject(err);
|
|
1508
|
+
resolve$1(null);
|
|
1509
|
+
});
|
|
1510
|
+
compilersWatching.push(watching);
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
const stats = await new Promise((resolve$1, reject) => compiler.run((err, stats$1) => err ? reject(err) : resolve$1(stats$1)));
|
|
1514
|
+
if (stats.hasErrors()) {
|
|
1515
|
+
const error = /* @__PURE__ */ new Error("Nuxt build error");
|
|
1516
|
+
error.stack = stats.toString("errors-only");
|
|
1517
|
+
throw error;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
function defineEventHandler(handler) {
|
|
1521
|
+
return Object.assign(handler, { __is_handler__: true });
|
|
1290
1522
|
}
|
|
1291
1523
|
|
|
1292
|
-
|
|
1524
|
+
//#endregion
|
|
1525
|
+
export { bundle };
|