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