vinext 0.0.41 → 0.0.42
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 +0 -1
- package/dist/build/client-build-config.d.ts +119 -0
- package/dist/build/client-build-config.js +149 -0
- package/dist/build/client-build-config.js.map +1 -0
- package/dist/build/layout-classification-types.d.ts +62 -0
- package/dist/build/layout-classification-types.js +1 -0
- package/dist/build/layout-classification.d.ts +60 -0
- package/dist/build/layout-classification.js +98 -0
- package/dist/build/layout-classification.js.map +1 -0
- package/dist/build/report.d.ts +15 -1
- package/dist/build/report.js +50 -1
- package/dist/build/report.js.map +1 -1
- package/dist/build/route-classification-manifest.d.ts +53 -0
- package/dist/build/route-classification-manifest.js +145 -0
- package/dist/build/route-classification-manifest.js.map +1 -0
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/ssr-manifest.d.ts +19 -0
- package/dist/build/ssr-manifest.js +71 -0
- package/dist/build/ssr-manifest.js.map +1 -0
- package/dist/check.js +2 -2
- package/dist/check.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/entry.js +1 -1
- package/dist/config/config-matchers.js +1 -0
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +287 -95
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/index.d.ts +1 -169
- package/dist/index.js +112 -432
- package/dist/index.js.map +1 -1
- package/dist/plugins/fonts.d.ts +49 -1
- package/dist/plugins/fonts.js +96 -3
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/postcss.d.ts +27 -0
- package/dist/plugins/postcss.js +94 -0
- package/dist/plugins/postcss.js.map +1 -0
- package/dist/plugins/strip-server-exports.d.ts +14 -0
- package/dist/plugins/strip-server-exports.js +73 -0
- package/dist/plugins/strip-server-exports.js.map +1 -0
- package/dist/routing/app-router.d.ts +6 -4
- package/dist/routing/app-router.js +21 -22
- package/dist/routing/app-router.js.map +1 -1
- package/dist/server/app-browser-entry.js +235 -97
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-error.d.ts +8 -0
- package/dist/server/app-browser-error.js +9 -0
- package/dist/server/app-browser-error.js.map +1 -0
- package/dist/server/app-browser-state.d.ts +93 -0
- package/dist/server/app-browser-state.js +132 -0
- package/dist/server/app-browser-state.js.map +1 -0
- package/dist/server/app-elements.d.ts +92 -0
- package/dist/server/app-elements.js +122 -0
- package/dist/server/app-elements.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +2 -1
- package/dist/server/app-page-boundary-render.js +40 -1
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +6 -3
- package/dist/server/app-page-cache.js +14 -8
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +36 -3
- package/dist/server/app-page-execution.js +50 -10
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +10 -4
- package/dist/server/app-page-probe.js +24 -15
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render.d.ts +7 -4
- package/dist/server/app-page-render.js +13 -4
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +52 -4
- package/dist/server/app-page-request.js +86 -16
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.d.ts +1 -0
- package/dist/server/app-page-response.js +1 -0
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +22 -8
- package/dist/server/app-page-route-wiring.js +219 -83
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-render-dependency.d.ts +13 -0
- package/dist/server/app-render-dependency.js +35 -0
- package/dist/server/app-render-dependency.js.map +1 -0
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +1 -0
- package/dist/server/app-route-handler-runtime.js +26 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-ssr-entry.js +6 -2
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/dev-server.js +2 -4
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/middleware.js +1 -5
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/prod-server.d.ts +3 -3
- package/dist/server/prod-server.js +1 -1
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +2 -1
- package/dist/server/request-pipeline.js +34 -5
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/shims/cache-runtime.d.ts +1 -0
- package/dist/shims/cache-runtime.js +0 -5
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +1 -0
- package/dist/shims/cache.js +1 -8
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/client-hook-error.d.ts +14 -0
- package/dist/shims/client-hook-error.js +19 -0
- package/dist/shims/client-hook-error.js.map +1 -0
- package/dist/shims/constants.d.ts +3 -3
- package/dist/shims/constants.js +3 -3
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/document.d.ts +6 -6
- package/dist/shims/error-boundary.d.ts +4 -4
- package/dist/shims/error-boundary.js +1 -1
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/form.d.ts +3 -3
- package/dist/shims/head-state.d.ts +1 -0
- package/dist/shims/head-state.js +0 -5
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/headers.d.ts +11 -0
- package/dist/shims/headers.js +13 -10
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-state.d.ts +1 -0
- package/dist/shims/i18n-state.js +0 -4
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/internal/app-router-context.d.ts +6 -6
- package/dist/shims/internal/router-context.d.ts +2 -2
- package/dist/shims/layout-segment-context.d.ts +2 -2
- package/dist/shims/link.js +19 -11
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +3 -3
- package/dist/shims/navigation-state.d.ts +2 -0
- package/dist/shims/navigation-state.js +0 -13
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +55 -8
- package/dist/shims/navigation.js +97 -23
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/navigation.react-server.d.ts +14 -0
- package/dist/shims/navigation.react-server.js +29 -0
- package/dist/shims/navigation.react-server.js.map +1 -0
- package/dist/shims/request-context.d.ts +1 -0
- package/dist/shims/request-context.js +0 -9
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router-state.js +0 -5
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/slot.d.ts +11 -7
- package/dist/shims/slot.js +28 -19
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +2 -0
- package/dist/shims/unified-request-context.js +0 -14
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/utils/mdx-scan.d.ts +10 -0
- package/dist/utils/mdx-scan.js +36 -0
- package/dist/utils/mdx-scan.js.map +1 -0
- package/dist/utils/public-routes.d.ts +5 -0
- package/dist/utils/public-routes.js +50 -0
- package/dist/utils/public-routes.js.map +1 -0
- package/package.json +3 -3
- package/dist/plugins/fix-use-server-closure-collision.d.ts +0 -29
- package/dist/plugins/fix-use-server-closure-collision.js +0 -204
- package/dist/plugins/fix-use-server-closure-collision.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
|
3
3
|
import { createValidFileMatcher } from "./routing/file-matcher.js";
|
|
4
4
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
5
5
|
import { buildRequestHeadersFromMiddlewareResponse } from "./server/middleware-request-headers.js";
|
|
6
|
-
import { isExternalUrl,
|
|
6
|
+
import { isExternalUrl, matchHeaders, matchRedirect, matchRewrite, proxyExternalRequest, requestContextFromRequest, sanitizeDestination } from "./config/config-matchers.js";
|
|
7
7
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
8
8
|
import { findMiddlewareFile, runMiddleware } from "./server/middleware.js";
|
|
9
9
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
@@ -19,21 +19,28 @@ import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
|
19
19
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
20
20
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
21
21
|
import { generateBrowserEntry } from "./entries/app-browser-entry.js";
|
|
22
|
+
import { buildGenerateBundleReplacement, buildReasonsReplacement, collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
23
|
+
import { classifyLayoutByModuleGraph, isStaticModuleGraphResult, moduleGraphReason } from "./build/layout-classification.js";
|
|
22
24
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
23
25
|
import { findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
24
26
|
import { precompressAssets } from "./build/precompress.js";
|
|
25
27
|
import { scanMetadataFiles } from "./server/metadata-routes.js";
|
|
26
|
-
import { manifestFileWithBase, manifestFilesWithBase
|
|
28
|
+
import { manifestFileWithBase, manifestFilesWithBase } from "./utils/manifest-paths.js";
|
|
27
29
|
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
|
|
28
30
|
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
|
|
29
31
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
30
32
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
31
|
-
import { fixUseServerClosureCollisionPlugin } from "./plugins/fix-use-server-closure-collision.js";
|
|
32
33
|
import { createOgInlineFetchAssetsPlugin, ogAssetsPlugin } from "./plugins/og-assets.js";
|
|
33
34
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
34
|
-
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS,
|
|
35
|
+
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
35
36
|
import { computeLazyChunks } from "./utils/lazy-chunks.js";
|
|
36
37
|
import { formatMissingCloudflarePluginError, hasWranglerConfig } from "./deploy.js";
|
|
38
|
+
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
39
|
+
import { createClientCodeSplittingConfig, createClientManualChunks, createClientOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
40
|
+
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
41
|
+
import { stripServerExports } from "./plugins/strip-server-exports.js";
|
|
42
|
+
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
43
|
+
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
37
44
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
38
45
|
import { createRequire } from "node:module";
|
|
39
46
|
import fs from "node:fs";
|
|
@@ -172,34 +179,6 @@ function getViteMajorVersion() {
|
|
|
172
179
|
return 7;
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
|
-
/**
|
|
176
|
-
* PostCSS config file names to search for, in priority order.
|
|
177
|
-
* Matches the same search order as postcss-load-config / lilconfig.
|
|
178
|
-
*/
|
|
179
|
-
const POSTCSS_CONFIG_FILES = [
|
|
180
|
-
"postcss.config.js",
|
|
181
|
-
"postcss.config.cjs",
|
|
182
|
-
"postcss.config.mjs",
|
|
183
|
-
"postcss.config.ts",
|
|
184
|
-
"postcss.config.cts",
|
|
185
|
-
"postcss.config.mts",
|
|
186
|
-
".postcssrc",
|
|
187
|
-
".postcssrc.js",
|
|
188
|
-
".postcssrc.cjs",
|
|
189
|
-
".postcssrc.mjs",
|
|
190
|
-
".postcssrc.ts",
|
|
191
|
-
".postcssrc.cts",
|
|
192
|
-
".postcssrc.mts",
|
|
193
|
-
".postcssrc.json",
|
|
194
|
-
".postcssrc.yaml",
|
|
195
|
-
".postcssrc.yml"
|
|
196
|
-
];
|
|
197
|
-
/**
|
|
198
|
-
* Module-level cache for resolvePostcssStringPlugins — avoids re-scanning per Vite environment.
|
|
199
|
-
* Stores the Promise itself so concurrent calls (RSC/SSR/Client config() hooks firing in
|
|
200
|
-
* parallel) all await the same in-flight scan rather than each starting their own.
|
|
201
|
-
*/
|
|
202
|
-
const _postcssCache = /* @__PURE__ */ new Map();
|
|
203
182
|
const _tsconfigAliasCache = /* @__PURE__ */ new Map();
|
|
204
183
|
function resolveTsconfigAliases(projectRoot) {
|
|
205
184
|
if (_tsconfigAliasCache.has(projectRoot)) return _tsconfigAliasCache.get(projectRoot);
|
|
@@ -213,63 +192,6 @@ function resolveTsconfigAliases(projectRoot) {
|
|
|
213
192
|
_tsconfigAliasCache.set(projectRoot, aliases);
|
|
214
193
|
return aliases;
|
|
215
194
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Resolve PostCSS string plugin names in a project's PostCSS config.
|
|
218
|
-
*
|
|
219
|
-
* Next.js (via postcss-load-config) resolves string plugin names in the
|
|
220
|
-
* object form `{ plugins: { "pkg-name": opts } }` but NOT in the array form
|
|
221
|
-
* `{ plugins: ["pkg-name"] }`. Since many Next.js projects use the array
|
|
222
|
-
* form (particularly with Tailwind CSS v4), we detect this case and resolve
|
|
223
|
-
* the string names to actual plugin functions so Vite can use them.
|
|
224
|
-
*
|
|
225
|
-
* Returns the resolved PostCSS config object to inject into Vite's
|
|
226
|
-
* `css.postcss`, or `undefined` if no resolution is needed.
|
|
227
|
-
*/
|
|
228
|
-
function resolvePostcssStringPlugins(projectRoot) {
|
|
229
|
-
if (_postcssCache.has(projectRoot)) return _postcssCache.get(projectRoot);
|
|
230
|
-
const promise = _resolvePostcssStringPluginsUncached(projectRoot);
|
|
231
|
-
_postcssCache.set(projectRoot, promise);
|
|
232
|
-
return promise;
|
|
233
|
-
}
|
|
234
|
-
async function _resolvePostcssStringPluginsUncached(projectRoot) {
|
|
235
|
-
let configPath = null;
|
|
236
|
-
for (const name of POSTCSS_CONFIG_FILES) {
|
|
237
|
-
const candidate = path.join(projectRoot, name);
|
|
238
|
-
if (fs.existsSync(candidate)) {
|
|
239
|
-
configPath = candidate;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (!configPath) return;
|
|
244
|
-
let config;
|
|
245
|
-
try {
|
|
246
|
-
if (configPath.endsWith(".json") || configPath.endsWith(".yaml") || configPath.endsWith(".yml")) return;
|
|
247
|
-
if (configPath.endsWith(".postcssrc")) {
|
|
248
|
-
if (fs.readFileSync(configPath, "utf-8").trim().startsWith("{")) return;
|
|
249
|
-
}
|
|
250
|
-
const mod = await import(pathToFileURL(configPath).href);
|
|
251
|
-
config = mod.default ?? mod;
|
|
252
|
-
} catch {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (!config || !Array.isArray(config.plugins)) return;
|
|
256
|
-
if (!config.plugins.some((p) => typeof p === "string" || Array.isArray(p) && typeof p[0] === "string")) return;
|
|
257
|
-
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
258
|
-
return { plugins: await Promise.all(config.plugins.filter(Boolean).map(async (plugin) => {
|
|
259
|
-
if (typeof plugin === "string") {
|
|
260
|
-
const mod = await import(pathToFileURL(req.resolve(plugin)).href);
|
|
261
|
-
const fn = mod.default ?? mod;
|
|
262
|
-
return typeof fn === "function" ? fn() : fn;
|
|
263
|
-
}
|
|
264
|
-
if (Array.isArray(plugin) && typeof plugin[0] === "string") {
|
|
265
|
-
const [name, options] = plugin;
|
|
266
|
-
const mod = await import(pathToFileURL(req.resolve(name)).href);
|
|
267
|
-
const fn = mod.default ?? mod;
|
|
268
|
-
return typeof fn === "function" ? fn(options) : fn;
|
|
269
|
-
}
|
|
270
|
-
return plugin;
|
|
271
|
-
})) };
|
|
272
|
-
}
|
|
273
195
|
const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
|
|
274
196
|
const RESOLVED_SERVER_ENTRY = "\0" + VIRTUAL_SERVER_ENTRY;
|
|
275
197
|
const VIRTUAL_CLIENT_ENTRY = "virtual:vinext-client-entry";
|
|
@@ -283,213 +205,34 @@ const RESOLVED_APP_BROWSER_ENTRY = "\0" + VIRTUAL_APP_BROWSER_ENTRY;
|
|
|
283
205
|
/** Image file extensions handled by the vinext:image-imports plugin.
|
|
284
206
|
* Shared between the Rolldown hook filter and the transform handler regex. */
|
|
285
207
|
const IMAGE_EXTS = "png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?";
|
|
286
|
-
/**
|
|
287
|
-
* Extract the npm package name from a module ID (file path).
|
|
288
|
-
* Returns null if not in node_modules.
|
|
289
|
-
*
|
|
290
|
-
* Handles scoped packages (@org/pkg) and pnpm-style paths
|
|
291
|
-
* (node_modules/.pnpm/pkg@ver/node_modules/pkg).
|
|
292
|
-
*/
|
|
293
|
-
function getPackageName(id) {
|
|
294
|
-
const nmIdx = id.lastIndexOf("node_modules/");
|
|
295
|
-
if (nmIdx === -1) return null;
|
|
296
|
-
const rest = id.slice(nmIdx + 13);
|
|
297
|
-
if (rest.startsWith("@")) {
|
|
298
|
-
const parts = rest.split("/");
|
|
299
|
-
return parts.length >= 2 ? parts[0] + "/" + parts[1] : null;
|
|
300
|
-
}
|
|
301
|
-
return rest.split("/")[0] || null;
|
|
302
|
-
}
|
|
303
208
|
/** Absolute path to vinext's shims directory, used by clientManualChunks. */
|
|
304
209
|
const _shimsDir = path.resolve(__dirname, "shims") + "/";
|
|
305
210
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
306
211
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* - "framework" — React, ReactDOM, and scheduler (loaded on every page)
|
|
311
|
-
* - "vinext" — vinext shims (router, head, link, etc.)
|
|
312
|
-
*
|
|
313
|
-
* All other vendor code is left to Rollup's default chunk-splitting
|
|
314
|
-
* algorithm. Rollup automatically deduplicates shared modules into
|
|
315
|
-
* common chunks based on the import graph — no manual intervention
|
|
316
|
-
* needed.
|
|
317
|
-
*
|
|
318
|
-
* Why not split every npm package into its own chunk?
|
|
319
|
-
* - Per-package splitting (`vendor-X`) creates 50-200+ chunks for a
|
|
320
|
-
* typical app, far exceeding the ~25-request sweet spot for HTTP/2.
|
|
321
|
-
* - gzip/brotli compress small files poorly — each file restarts with
|
|
322
|
-
* an empty dictionary, losing ~5-15% total compressed size vs fewer
|
|
323
|
-
* larger chunks (Khan Academy measured +2.5% wire size with 10x
|
|
324
|
-
* more files containing less raw code).
|
|
325
|
-
* - ES module evaluation has per-module overhead that compounds on
|
|
326
|
-
* mobile devices.
|
|
327
|
-
* - No major Vite-based framework (Remix, SvelteKit, Astro, TanStack)
|
|
328
|
-
* uses per-package splitting. Next.js only isolates packages >160KB.
|
|
329
|
-
* - Rollup's graph-based splitting already handles the common case
|
|
330
|
-
* well: shared dependencies between routes get their own chunks,
|
|
331
|
-
* and route-specific code stays in route chunks.
|
|
332
|
-
*/
|
|
333
|
-
function clientManualChunks(id) {
|
|
334
|
-
if (id.includes("node_modules")) {
|
|
335
|
-
const pkg = getPackageName(id);
|
|
336
|
-
if (!pkg) return void 0;
|
|
337
|
-
if (pkg === "react" || pkg === "react-dom" || pkg === "scheduler") return "framework";
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
if (id.startsWith(_shimsDir)) return "vinext";
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Rollup output config with manualChunks for client code-splitting.
|
|
344
|
-
* Used by both CLI builds and multi-environment builds.
|
|
345
|
-
*
|
|
346
|
-
* experimentalMinChunkSize merges tiny shared chunks (< 10KB) back into
|
|
347
|
-
* their importers. This reduces HTTP request count and improves gzip
|
|
348
|
-
* compression efficiency — small files restart the compression dictionary,
|
|
349
|
-
* adding ~5-15% wire overhead vs fewer larger chunks.
|
|
350
|
-
*/
|
|
351
|
-
const clientOutputConfig = {
|
|
352
|
-
manualChunks: clientManualChunks,
|
|
353
|
-
experimentalMinChunkSize: 1e4
|
|
354
|
-
};
|
|
355
|
-
const clientCodeSplittingConfig = {
|
|
356
|
-
minSize: 1e4,
|
|
357
|
-
groups: [{ name(moduleId) {
|
|
358
|
-
return clientManualChunks(moduleId) ?? null;
|
|
359
|
-
} }]
|
|
360
|
-
};
|
|
361
|
-
/**
|
|
362
|
-
* Rollup treeshake configuration for production client builds.
|
|
363
|
-
*
|
|
364
|
-
* Uses the 'recommended' preset as a safe base, then overrides
|
|
365
|
-
* moduleSideEffects to strip unused re-exports from npm packages.
|
|
212
|
+
* Shims with a `.react-server.ts` variant for the RSC environment.
|
|
213
|
+
* Maps import specifier → base shim name. In the RSC env, resolveId
|
|
214
|
+
* appends `.react-server`; in other envs it resolves to the base.
|
|
366
215
|
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
216
|
+
* These MUST NOT appear in `nextShimMap` (resolve.alias) because Vite's
|
|
217
|
+
* alias plugin runs before user `enforce:"pre"` plugins — aliases are
|
|
218
|
+
* unoverridable. Keeping them out of the alias lets the resolveId hook
|
|
219
|
+
* control resolution per-environment.
|
|
370
220
|
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* Rollup preserves every sub-module even when only a few exports are consumed.
|
|
375
|
-
*
|
|
376
|
-
* Why 'no-external' instead of false (global side-effect-free)?
|
|
377
|
-
* - User code may rely on import-time side effects (e.g., `import './global.css'`)
|
|
378
|
-
* - 'no-external' is safe for app code while still enabling aggressive DCE for deps
|
|
379
|
-
*
|
|
380
|
-
* Why not the 'smallest' preset?
|
|
381
|
-
* - 'smallest' also sets propertyReadSideEffects: false and
|
|
382
|
-
* tryCatchDeoptimization: false, which can break specific libraries
|
|
383
|
-
* that rely on property access side effects or try/catch for feature detection
|
|
384
|
-
* - 'recommended' + 'no-external' gives most of the benefit with less risk
|
|
385
|
-
*
|
|
386
|
-
* @deprecated Use getClientTreeshakeConfigForVite(viteMajorVersion) instead
|
|
387
|
-
* for Vite version compatibility. Kept for backward compatibility.
|
|
221
|
+
* To add a new react-server shim:
|
|
222
|
+
* 1. Create `<name>.react-server.ts` in src/shims/
|
|
223
|
+
* 2. Add entries here for each import specifier.
|
|
388
224
|
*/
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
function withBuildBundlerOptions(viteMajorVersion, bundlerOptions) {
|
|
398
|
-
return viteMajorVersion >= 8 ? { rolldownOptions: bundlerOptions } : { rollupOptions: bundlerOptions };
|
|
399
|
-
}
|
|
225
|
+
const _reactServerShims = new Map([
|
|
226
|
+
["next/navigation", "navigation"],
|
|
227
|
+
["next/navigation.js", "navigation"],
|
|
228
|
+
["next/dist/client/components/navigation", "navigation"]
|
|
229
|
+
]);
|
|
230
|
+
const clientManualChunks = createClientManualChunks(_shimsDir);
|
|
231
|
+
const clientOutputConfig = createClientOutputConfig(clientManualChunks);
|
|
232
|
+
const clientCodeSplittingConfig = createClientCodeSplittingConfig(clientManualChunks);
|
|
400
233
|
function getClientOutputConfigForVite(viteMajorVersion) {
|
|
401
234
|
return viteMajorVersion >= 8 ? { codeSplitting: clientCodeSplittingConfig } : clientOutputConfig;
|
|
402
235
|
}
|
|
403
|
-
/**
|
|
404
|
-
* Returns treeshake configuration appropriate for the Vite version.
|
|
405
|
-
*
|
|
406
|
-
* Rollup (Vite 7) supports presets like "recommended" which set multiple
|
|
407
|
-
* treeshake options at once. Rolldown (Vite 8+) doesn't support presets,
|
|
408
|
-
* so we only return moduleSideEffects for Vite 8+.
|
|
409
|
-
*
|
|
410
|
-
* The Rollup "recommended" preset sets:
|
|
411
|
-
* - annotations: true (Rolldown default is also true)
|
|
412
|
-
* - manualPureFunctions: [] (Rolldown default is also [])
|
|
413
|
-
* - propertyReadSideEffects: true (Rolldown equivalent is 'always', the default)
|
|
414
|
-
* - unknownGlobalSideEffects: false (Rolldown default is true — this is a known acceptable
|
|
415
|
-
* divergence. Slightly less aggressive DCE on unknown globals, acceptable for client bundles)
|
|
416
|
-
* - correctVarValueBeforeDeclaration and tryCatchDeoptimization (Rolldown handles these differently)
|
|
417
|
-
*
|
|
418
|
-
* The key optimization is moduleSideEffects: "no-external", which is supported
|
|
419
|
-
* by both bundlers and provides the DCE benefits for barrel-exporting libraries.
|
|
420
|
-
* It treats node_modules as side-effect-free (enabling aggressive DCE) while
|
|
421
|
-
* preserving side effects in local code.
|
|
422
|
-
*/
|
|
423
|
-
function getClientTreeshakeConfigForVite(viteMajorVersion) {
|
|
424
|
-
if (viteMajorVersion >= 8) return { moduleSideEffects: "no-external" };
|
|
425
|
-
return {
|
|
426
|
-
preset: "recommended",
|
|
427
|
-
moduleSideEffects: "no-external"
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
function tryRealpathSync(candidate) {
|
|
431
|
-
try {
|
|
432
|
-
return fs.realpathSync.native(candidate);
|
|
433
|
-
} catch {
|
|
434
|
-
return null;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
function isWindowsAbsolutePath(candidate) {
|
|
438
|
-
return /^[a-zA-Z]:[\\/]/.test(candidate) || candidate.startsWith("\\\\");
|
|
439
|
-
}
|
|
440
|
-
function relativeWithinRoot(root, moduleId) {
|
|
441
|
-
const relativeId = (isWindowsAbsolutePath(root) || isWindowsAbsolutePath(moduleId) ? path.win32.relative(root, moduleId) : path.relative(root, moduleId)).replace(/\\/g, "/");
|
|
442
|
-
if (!relativeId || relativeId === ".." || relativeId.startsWith("../")) return null;
|
|
443
|
-
return relativeId;
|
|
444
|
-
}
|
|
445
|
-
function normalizeManifestModuleId(moduleId, root) {
|
|
446
|
-
const normalizedId = moduleId.replace(/\\/g, "/");
|
|
447
|
-
if (normalizedId.startsWith("\0")) return normalizedId;
|
|
448
|
-
if (normalizedId.startsWith("node_modules/") || normalizedId.includes("/node_modules/")) return normalizedId;
|
|
449
|
-
if (!isWindowsAbsolutePath(moduleId) && !path.isAbsolute(moduleId)) {
|
|
450
|
-
if (!normalizedId.startsWith(".") && !normalizedId.includes("../")) return normalizedId;
|
|
451
|
-
}
|
|
452
|
-
const rootCandidates = new Set([root]);
|
|
453
|
-
const realRoot = tryRealpathSync(root);
|
|
454
|
-
if (realRoot) rootCandidates.add(realRoot);
|
|
455
|
-
const moduleCandidates = /* @__PURE__ */ new Set();
|
|
456
|
-
if (isWindowsAbsolutePath(moduleId) || path.isAbsolute(moduleId)) moduleCandidates.add(moduleId);
|
|
457
|
-
else moduleCandidates.add(path.resolve(root, moduleId));
|
|
458
|
-
for (const candidate of moduleCandidates) {
|
|
459
|
-
const realCandidate = tryRealpathSync(candidate);
|
|
460
|
-
if (realCandidate) moduleCandidates.add(realCandidate);
|
|
461
|
-
}
|
|
462
|
-
for (const rootCandidate of rootCandidates) for (const moduleCandidate of moduleCandidates) {
|
|
463
|
-
const relativeId = relativeWithinRoot(rootCandidate, moduleCandidate);
|
|
464
|
-
if (relativeId) return relativeId;
|
|
465
|
-
}
|
|
466
|
-
return normalizedId;
|
|
467
|
-
}
|
|
468
|
-
function augmentSsrManifestFromBundle(ssrManifest, bundle, root, base = "/") {
|
|
469
|
-
const nextManifest = {};
|
|
470
|
-
for (const [key, files] of Object.entries(ssrManifest)) {
|
|
471
|
-
const normalizedKey = normalizeManifestModuleId(key, root);
|
|
472
|
-
if (!nextManifest[normalizedKey]) nextManifest[normalizedKey] = /* @__PURE__ */ new Set();
|
|
473
|
-
for (const file of files) nextManifest[normalizedKey].add(normalizeManifestFile(file));
|
|
474
|
-
}
|
|
475
|
-
for (const item of Object.values(bundle)) {
|
|
476
|
-
if (item.type !== "chunk") continue;
|
|
477
|
-
const chunk = item;
|
|
478
|
-
const files = /* @__PURE__ */ new Set();
|
|
479
|
-
files.add(manifestFileWithBase(chunk.fileName, base));
|
|
480
|
-
for (const importedFile of chunk.imports ?? []) files.add(manifestFileWithBase(importedFile, base));
|
|
481
|
-
for (const cssFile of chunk.viteMetadata?.importedCss ?? []) files.add(manifestFileWithBase(cssFile, base));
|
|
482
|
-
for (const assetFile of chunk.viteMetadata?.importedAssets ?? []) files.add(manifestFileWithBase(assetFile, base));
|
|
483
|
-
for (const moduleId of Object.keys(chunk.modules ?? {})) {
|
|
484
|
-
const key = normalizeManifestModuleId(moduleId, root);
|
|
485
|
-
if (key.startsWith("node_modules/") || key.includes("/node_modules/")) continue;
|
|
486
|
-
if (key.startsWith("\0")) continue;
|
|
487
|
-
if (!nextManifest[key]) nextManifest[key] = /* @__PURE__ */ new Set();
|
|
488
|
-
for (const file of files) nextManifest[key].add(file);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return Object.fromEntries(Object.entries(nextManifest).map(([key, files]) => [key, [...files]]));
|
|
492
|
-
}
|
|
493
236
|
function vinext(options = {}) {
|
|
494
237
|
const viteMajorVersion = getViteMajorVersion();
|
|
495
238
|
let root;
|
|
@@ -505,7 +248,14 @@ function vinext(options = {}) {
|
|
|
505
248
|
let hasCloudflarePlugin = false;
|
|
506
249
|
let warnedInlineNextConfigOverride = false;
|
|
507
250
|
let hasNitroPlugin = false;
|
|
251
|
+
let rscClassificationManifest = null;
|
|
508
252
|
const shimsDir = path.resolve(__dirname, "shims");
|
|
253
|
+
const canonicalize = (p) => tryRealpathSync(p) ?? p;
|
|
254
|
+
const dynamicShimPaths = new Set([
|
|
255
|
+
resolveShimModulePath(shimsDir, "headers"),
|
|
256
|
+
resolveShimModulePath(shimsDir, "server"),
|
|
257
|
+
resolveShimModulePath(shimsDir, "cache")
|
|
258
|
+
].map(canonicalize));
|
|
509
259
|
let nextShimMap = {};
|
|
510
260
|
/**
|
|
511
261
|
* Generate the virtual SSR server entry module.
|
|
@@ -593,7 +343,6 @@ function vinext(options = {}) {
|
|
|
593
343
|
...viteMajorVersion >= 8 ? [] : [tsconfigPaths()],
|
|
594
344
|
reactPluginPromise,
|
|
595
345
|
commonjs(),
|
|
596
|
-
fixUseServerClosureCollisionPlugin,
|
|
597
346
|
{
|
|
598
347
|
name: "vinext:config",
|
|
599
348
|
enforce: "pre",
|
|
@@ -691,7 +440,6 @@ function vinext(options = {}) {
|
|
|
691
440
|
"next/config": path.join(shimsDir, "config"),
|
|
692
441
|
"next/script": path.join(shimsDir, "script"),
|
|
693
442
|
"next/server": path.join(shimsDir, "server"),
|
|
694
|
-
"next/navigation": path.join(shimsDir, "navigation"),
|
|
695
443
|
"next/headers": path.join(shimsDir, "headers"),
|
|
696
444
|
"next/font/google": path.join(shimsDir, "font-google"),
|
|
697
445
|
"next/font/local": path.join(shimsDir, "font-local"),
|
|
@@ -713,7 +461,6 @@ function vinext(options = {}) {
|
|
|
713
461
|
"next/dist/client/components/work-unit-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
714
462
|
"next/dist/client/components/request-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
715
463
|
"next/dist/client/components/request-async-storage": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
716
|
-
"next/dist/client/components/navigation": path.join(shimsDir, "navigation"),
|
|
717
464
|
"next/dist/server/config-shared": path.join(shimsDir, "internal", "utils"),
|
|
718
465
|
"server-only": path.join(shimsDir, "server-only"),
|
|
719
466
|
"client-only": path.join(shimsDir, "client-only"),
|
|
@@ -799,13 +546,22 @@ function vinext(options = {}) {
|
|
|
799
546
|
const userSsrExternal = Array.isArray(config.ssr?.external) ? [...config.ssr.external, ...nextServerExternal] : config.ssr?.external === true ? true : nextServerExternal;
|
|
800
547
|
const incomingExclude = config.optimizeDeps?.exclude ?? [];
|
|
801
548
|
const incomingInclude = config.optimizeDeps?.include ?? [];
|
|
549
|
+
const depOptimizeAliasPlugin = {
|
|
550
|
+
name: "vinext:dep-optimize-alias",
|
|
551
|
+
resolveId(id) {
|
|
552
|
+
const shimBase = _reactServerShims.get(id);
|
|
553
|
+
if (shimBase !== void 0) return resolveShimModulePath(shimsDir, shimBase);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
802
556
|
viteConfig.optimizeDeps = {
|
|
803
557
|
exclude: [...new Set([
|
|
804
558
|
...incomingExclude,
|
|
805
559
|
"vinext",
|
|
806
|
-
"@vercel/og"
|
|
560
|
+
"@vercel/og",
|
|
561
|
+
"@tailwindcss/oxide"
|
|
807
562
|
])],
|
|
808
|
-
...incomingInclude.length > 0 ? { include: incomingInclude } : {}
|
|
563
|
+
...incomingInclude.length > 0 ? { include: incomingInclude } : {},
|
|
564
|
+
rolldownOptions: { plugins: [depOptimizeAliasPlugin] }
|
|
809
565
|
};
|
|
810
566
|
const pagesOptimizeEntries = !hasAppDir ? [...hasPagesDir ? [toRelativeFileEntry(root, pagesDir) + "/**/*.{tsx,ts,jsx,js}"] : [], ...[instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : [])] : [];
|
|
811
567
|
if (hasAppDir) {
|
|
@@ -971,6 +727,8 @@ function vinext(options = {}) {
|
|
|
971
727
|
const queryIndex = cleanId.indexOf(VIRTUAL_GOOGLE_FONTS + "?");
|
|
972
728
|
return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(queryIndex + VIRTUAL_GOOGLE_FONTS.length);
|
|
973
729
|
}
|
|
730
|
+
const reactServerShim = _reactServerShims.get(cleanId);
|
|
731
|
+
if (reactServerShim !== void 0) return resolveShimModulePath(_shimsDir, this.environment?.name === "rsc" ? `${reactServerShim}.react-server` : reactServerShim);
|
|
974
732
|
}
|
|
975
733
|
},
|
|
976
734
|
async load(id) {
|
|
@@ -980,6 +738,7 @@ function vinext(options = {}) {
|
|
|
980
738
|
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
981
739
|
const metaRoutes = scanMetadataFiles(appDir);
|
|
982
740
|
const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
|
|
741
|
+
rscClassificationManifest = collectRouteClassificationManifest(routes);
|
|
983
742
|
return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
|
|
984
743
|
redirects: nextConfig?.redirects,
|
|
985
744
|
rewrites: nextConfig?.rewrites,
|
|
@@ -995,6 +754,66 @@ function vinext(options = {}) {
|
|
|
995
754
|
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
|
|
996
755
|
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) return generateBrowserEntry();
|
|
997
756
|
if (id.startsWith("\0virtual:vinext-google-fonts?")) return generateGoogleFontsVirtualModule(id, _fontGoogleShimPath);
|
|
757
|
+
},
|
|
758
|
+
generateBundle(_options, bundle) {
|
|
759
|
+
if (this.environment?.name !== "rsc") return;
|
|
760
|
+
if (!rscClassificationManifest) return;
|
|
761
|
+
const enableClassificationDebug = Boolean(process.env.VINEXT_DEBUG_CLASSIFICATION);
|
|
762
|
+
const stubRe = /function __VINEXT_CLASS\(routeIdx\)\s*\{\s*return null;?\s*\}/;
|
|
763
|
+
const reasonsStubRe = /function __VINEXT_CLASS_REASONS\(routeIdx\)\s*\{\s*return null;?\s*\}/;
|
|
764
|
+
const chunksMentioningStub = [];
|
|
765
|
+
const chunksWithStubBody = [];
|
|
766
|
+
for (const chunk of Object.values(bundle)) {
|
|
767
|
+
if (chunk.type !== "chunk") continue;
|
|
768
|
+
if (!chunk.code.includes("__VINEXT_CLASS")) continue;
|
|
769
|
+
chunksMentioningStub.push({
|
|
770
|
+
chunk,
|
|
771
|
+
fileName: chunk.fileName
|
|
772
|
+
});
|
|
773
|
+
if (stubRe.test(chunk.code)) chunksWithStubBody.push({
|
|
774
|
+
chunk,
|
|
775
|
+
fileName: chunk.fileName
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
if (chunksMentioningStub.length === 0) return;
|
|
779
|
+
if (chunksWithStubBody.length === 0) throw new Error(`vinext: build-time classification — __VINEXT_CLASS is referenced in ${chunksMentioningStub.map((c) => c.fileName).join(", ")} but no chunk contains the stub body. The generator and generateBundle have drifted.`);
|
|
780
|
+
if (chunksWithStubBody.length > 1) throw new Error(`vinext: build-time classification — expected __VINEXT_CLASS stub in exactly one RSC chunk, found ${chunksWithStubBody.length}`);
|
|
781
|
+
if (enableClassificationDebug && !reasonsStubRe.test(chunksWithStubBody[0].chunk.code)) throw new Error("vinext: build-time classification — __VINEXT_CLASS_REASONS stub is missing alongside __VINEXT_CLASS. The generator and generateBundle have drifted.");
|
|
782
|
+
const moduleInfo = { getModuleInfo: (moduleId) => {
|
|
783
|
+
const info = this.getModuleInfo(moduleId);
|
|
784
|
+
if (!info) return null;
|
|
785
|
+
return {
|
|
786
|
+
importedIds: info.importedIds ?? [],
|
|
787
|
+
dynamicImportedIds: info.dynamicallyImportedIds ?? []
|
|
788
|
+
};
|
|
789
|
+
} };
|
|
790
|
+
const layer2PerRoute = /* @__PURE__ */ new Map();
|
|
791
|
+
const graphCache = /* @__PURE__ */ new Map();
|
|
792
|
+
for (let routeIdx = 0; routeIdx < rscClassificationManifest.routes.length; routeIdx++) {
|
|
793
|
+
const route = rscClassificationManifest.routes[routeIdx];
|
|
794
|
+
const perRoute = /* @__PURE__ */ new Map();
|
|
795
|
+
for (let layoutIdx = 0; layoutIdx < route.layoutPaths.length; layoutIdx++) {
|
|
796
|
+
if (route.layer1.has(layoutIdx)) continue;
|
|
797
|
+
const layoutModuleId = canonicalize(route.layoutPaths[layoutIdx]);
|
|
798
|
+
if (!moduleInfo.getModuleInfo(layoutModuleId)) continue;
|
|
799
|
+
let graphResult = graphCache.get(layoutModuleId);
|
|
800
|
+
if (graphResult === void 0) {
|
|
801
|
+
graphResult = classifyLayoutByModuleGraph(layoutModuleId, dynamicShimPaths, moduleInfo);
|
|
802
|
+
graphCache.set(layoutModuleId, graphResult);
|
|
803
|
+
}
|
|
804
|
+
if (isStaticModuleGraphResult(graphResult)) perRoute.set(layoutIdx, moduleGraphReason(graphResult));
|
|
805
|
+
}
|
|
806
|
+
if (perRoute.size > 0) layer2PerRoute.set(routeIdx, perRoute);
|
|
807
|
+
}
|
|
808
|
+
const patchedBody = `function __VINEXT_CLASS(routeIdx) { return (${buildGenerateBundleReplacement(rscClassificationManifest, layer2PerRoute)})(routeIdx); }`;
|
|
809
|
+
const target = chunksWithStubBody[0].chunk;
|
|
810
|
+
target.code = target.code.replace(stubRe, patchedBody);
|
|
811
|
+
if (enableClassificationDebug) {
|
|
812
|
+
const patchedReasonsBody = `function __VINEXT_CLASS_REASONS(routeIdx) { return (${buildReasonsReplacement(rscClassificationManifest, layer2PerRoute)})(routeIdx); }`;
|
|
813
|
+
target.code = target.code.replace(reasonsStubRe, patchedReasonsBody);
|
|
814
|
+
}
|
|
815
|
+
target.map = null;
|
|
816
|
+
rscClassificationManifest = null;
|
|
998
817
|
}
|
|
999
818
|
},
|
|
1000
819
|
asyncHooksStubPlugin,
|
|
@@ -1320,8 +1139,7 @@ function vinext(options = {}) {
|
|
|
1320
1139
|
}
|
|
1321
1140
|
}
|
|
1322
1141
|
const reqUrl = new URL(url, requestOrigin);
|
|
1323
|
-
const
|
|
1324
|
-
const reqCtx = requestContextFromRequest(new Request(reqUrl, { headers: reqCtxHeaders }));
|
|
1142
|
+
const reqCtx = requestContextFromRequest(new Request(reqUrl, { headers: middlewareRequestHeaders ?? nodeRequestHeaders }));
|
|
1325
1143
|
if (nextConfig?.headers.length) applyHeaders(pathname, res, nextConfig.headers, preMiddlewareReqCtx);
|
|
1326
1144
|
let resolvedUrl = url;
|
|
1327
1145
|
if (nextConfig?.rewrites.beforeFiles.length) resolvedUrl = applyRewrites(pathname, nextConfig.rewrites.beforeFiles, reqCtx) ?? url;
|
|
@@ -1891,72 +1709,6 @@ function getNextPublicEnvDefines() {
|
|
|
1891
1709
|
return defines;
|
|
1892
1710
|
}
|
|
1893
1711
|
/**
|
|
1894
|
-
* Strip server-only data-fetching exports (getServerSideProps,
|
|
1895
|
-
* getStaticProps, getStaticPaths) from page modules for the client
|
|
1896
|
-
* bundle. Uses Vite's parseAst (Rollup/acorn) for correct handling
|
|
1897
|
-
* of all export patterns including function expressions, arrow
|
|
1898
|
-
* functions with TS return types, and re-exports.
|
|
1899
|
-
*
|
|
1900
|
-
* Modeled after Next.js's SWC `next-ssg-transform`.
|
|
1901
|
-
*/
|
|
1902
|
-
function stripServerExports(code) {
|
|
1903
|
-
const SERVER_EXPORTS = new Set([
|
|
1904
|
-
"getServerSideProps",
|
|
1905
|
-
"getStaticProps",
|
|
1906
|
-
"getStaticPaths"
|
|
1907
|
-
]);
|
|
1908
|
-
if (![...SERVER_EXPORTS].some((name) => code.includes(name))) return null;
|
|
1909
|
-
let ast;
|
|
1910
|
-
try {
|
|
1911
|
-
ast = parseAst(code);
|
|
1912
|
-
} catch {
|
|
1913
|
-
return null;
|
|
1914
|
-
}
|
|
1915
|
-
const s = new MagicString(code);
|
|
1916
|
-
let changed = false;
|
|
1917
|
-
for (const node of ast.body) {
|
|
1918
|
-
if (node.type !== "ExportNamedDeclaration") continue;
|
|
1919
|
-
if (node.declaration) {
|
|
1920
|
-
const decl = node.declaration;
|
|
1921
|
-
if (decl.type === "FunctionDeclaration" && decl.id && SERVER_EXPORTS.has(decl.id.name)) {
|
|
1922
|
-
s.overwrite(node.start, node.end, `export function ${decl.id.name}() { return { props: {} }; }`);
|
|
1923
|
-
changed = true;
|
|
1924
|
-
} else if (decl.type === "VariableDeclaration") {
|
|
1925
|
-
for (const declarator of decl.declarations) if (declarator.id?.type === "Identifier" && SERVER_EXPORTS.has(declarator.id.name)) {
|
|
1926
|
-
s.overwrite(node.start, node.end, `export const ${declarator.id.name} = undefined;`);
|
|
1927
|
-
changed = true;
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
continue;
|
|
1931
|
-
}
|
|
1932
|
-
if (node.specifiers && node.specifiers.length > 0 && !node.source) {
|
|
1933
|
-
const kept = [];
|
|
1934
|
-
const stripped = [];
|
|
1935
|
-
for (const spec of node.specifiers) {
|
|
1936
|
-
const exportedName = spec.exported?.name ?? spec.exported?.value;
|
|
1937
|
-
if (SERVER_EXPORTS.has(exportedName)) stripped.push(exportedName);
|
|
1938
|
-
else kept.push(spec);
|
|
1939
|
-
}
|
|
1940
|
-
if (stripped.length > 0) {
|
|
1941
|
-
const parts = [];
|
|
1942
|
-
if (kept.length > 0) {
|
|
1943
|
-
const keptStr = kept.map((sp) => {
|
|
1944
|
-
const local = sp.local.name;
|
|
1945
|
-
const exported = sp.exported?.name ?? sp.exported?.value;
|
|
1946
|
-
return local === exported ? local : `${local} as ${exported}`;
|
|
1947
|
-
}).join(", ");
|
|
1948
|
-
parts.push(`export { ${keptStr} };`);
|
|
1949
|
-
}
|
|
1950
|
-
for (const name of stripped) parts.push(`export const ${name} = undefined;`);
|
|
1951
|
-
s.overwrite(node.start, node.end, parts.join("\n"));
|
|
1952
|
-
changed = true;
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
if (!changed) return null;
|
|
1957
|
-
return s.toString();
|
|
1958
|
-
}
|
|
1959
|
-
/**
|
|
1960
1712
|
* Apply redirect rules from next.config.js.
|
|
1961
1713
|
* Returns true if a redirect was applied.
|
|
1962
1714
|
*/
|
|
@@ -2045,79 +1797,7 @@ function findFileWithExts(dir, name, matcher) {
|
|
|
2045
1797
|
}
|
|
2046
1798
|
return null;
|
|
2047
1799
|
}
|
|
2048
|
-
/** Module-level cache for hasMdxFiles — avoids re-scanning per Vite environment. */
|
|
2049
|
-
const _mdxScanCache = /* @__PURE__ */ new Map();
|
|
2050
|
-
/**
|
|
2051
|
-
* Check if the project has .mdx files in app/ or pages/ directories.
|
|
2052
|
-
*/
|
|
2053
|
-
function hasMdxFiles(root, appDir, pagesDir) {
|
|
2054
|
-
const cacheKey = `${root}\0${appDir ?? ""}\0${pagesDir ?? ""}`;
|
|
2055
|
-
if (_mdxScanCache.has(cacheKey)) return _mdxScanCache.get(cacheKey);
|
|
2056
|
-
const dirs = [appDir, pagesDir].filter(Boolean);
|
|
2057
|
-
for (const dir of dirs) if (fs.existsSync(dir) && scanDirForMdx(dir)) {
|
|
2058
|
-
_mdxScanCache.set(cacheKey, true);
|
|
2059
|
-
return true;
|
|
2060
|
-
}
|
|
2061
|
-
_mdxScanCache.set(cacheKey, false);
|
|
2062
|
-
return false;
|
|
2063
|
-
}
|
|
2064
|
-
function scanDirForMdx(dir) {
|
|
2065
|
-
try {
|
|
2066
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
2067
|
-
for (const entry of entries) {
|
|
2068
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
2069
|
-
const full = path.join(dir, entry.name);
|
|
2070
|
-
if (entry.isDirectory()) {
|
|
2071
|
-
if (scanDirForMdx(full)) return true;
|
|
2072
|
-
} else if (entry.isFile() && entry.name.toLowerCase().endsWith(".mdx")) return true;
|
|
2073
|
-
}
|
|
2074
|
-
} catch {}
|
|
2075
|
-
return false;
|
|
2076
|
-
}
|
|
2077
|
-
function scanPublicFileRoutes(root) {
|
|
2078
|
-
const publicDir = path.join(root, "public");
|
|
2079
|
-
const routes = [];
|
|
2080
|
-
const visitedDirs = /* @__PURE__ */ new Set();
|
|
2081
|
-
function walk(dir) {
|
|
2082
|
-
let realDir;
|
|
2083
|
-
try {
|
|
2084
|
-
realDir = fs.realpathSync(dir);
|
|
2085
|
-
} catch {
|
|
2086
|
-
return;
|
|
2087
|
-
}
|
|
2088
|
-
if (visitedDirs.has(realDir)) return;
|
|
2089
|
-
visitedDirs.add(realDir);
|
|
2090
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
2091
|
-
for (const entry of entries) {
|
|
2092
|
-
const fullPath = path.join(dir, entry.name);
|
|
2093
|
-
if (entry.isDirectory()) {
|
|
2094
|
-
walk(fullPath);
|
|
2095
|
-
continue;
|
|
2096
|
-
}
|
|
2097
|
-
if (entry.isSymbolicLink()) {
|
|
2098
|
-
let stat;
|
|
2099
|
-
try {
|
|
2100
|
-
stat = fs.statSync(fullPath);
|
|
2101
|
-
} catch {
|
|
2102
|
-
continue;
|
|
2103
|
-
}
|
|
2104
|
-
if (stat.isDirectory()) {
|
|
2105
|
-
walk(fullPath);
|
|
2106
|
-
continue;
|
|
2107
|
-
}
|
|
2108
|
-
if (!stat.isFile()) continue;
|
|
2109
|
-
} else if (!entry.isFile()) continue;
|
|
2110
|
-
const relativePath = path.relative(publicDir, fullPath).split(path.sep).join("/");
|
|
2111
|
-
routes.push("/" + relativePath);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
if (fs.existsSync(publicDir)) try {
|
|
2115
|
-
walk(publicDir);
|
|
2116
|
-
} catch {}
|
|
2117
|
-
routes.sort();
|
|
2118
|
-
return routes;
|
|
2119
|
-
}
|
|
2120
1800
|
//#endregion
|
|
2121
|
-
export {
|
|
1801
|
+
export { vinext as default, staticExportApp, staticExportPages };
|
|
2122
1802
|
|
|
2123
1803
|
//# sourceMappingURL=index.js.map
|