vinext 0.2.1 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -29
- package/dist/build/client-build-config.d.ts +13 -92
- package/dist/build/client-build-config.js +17 -95
- package/dist/build/prerender-paths.d.ts +23 -0
- package/dist/build/prerender-paths.js +296 -0
- package/dist/build/prerender.d.ts +12 -1
- package/dist/build/prerender.js +1 -1
- package/dist/cache/cache-adapters-virtual.d.ts +7 -1
- package/dist/cache/cache-adapters-virtual.js +26 -2
- package/dist/check.js +5 -0
- package/dist/cli.js +33 -53
- package/dist/config/next-config.js +1 -2
- package/dist/config/prerender.d.ts +11 -1
- package/dist/config/prerender.js +19 -1
- package/dist/config/tsconfig-paths.js +5 -1
- package/dist/image/image-adapters-virtual.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +248 -146
- package/dist/init-cloudflare.js +12 -3
- package/dist/init-platform.d.ts +10 -1
- package/dist/init-platform.js +78 -12
- package/dist/init.d.ts +11 -3
- package/dist/init.js +129 -31
- package/dist/server/app-browser-entry.js +4 -6
- package/dist/server/app-browser-navigation-controller.js +6 -3
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-layout-param-observation.d.ts +1 -1
- package/dist/server/app-page-cache-render.d.ts +1 -1
- package/dist/server/app-page-dispatch.d.ts +1 -1
- package/dist/server/app-page-dispatch.js +3 -3
- package/dist/server/app-page-render.d.ts +1 -1
- package/dist/server/app-page-route-wiring.js +3 -3
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-rsc-cache-busting.js +0 -1
- package/dist/server/app-rsc-handler.js +1 -1
- package/dist/server/app-rsc-render-mode.d.ts +2 -5
- package/dist/server/app-rsc-render-mode.js +2 -12
- package/dist/server/app-server-action-execution.js +4 -4
- package/dist/server/app-ssr-entry.js +2 -2
- package/dist/server/dev-module-runner.js +1 -1
- package/dist/server/dev-origin-check.d.ts +2 -2
- package/dist/server/dev-origin-check.js +2 -2
- package/dist/server/dev-server.js +4 -4
- package/dist/server/image-optimization.d.ts +12 -1
- package/dist/server/image-optimization.js +13 -1
- package/dist/server/isr-cache.d.ts +12 -4
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/pages-page-data.js +1 -1
- package/dist/server/pages-page-response.js +2 -2
- package/dist/server/pages-request-pipeline.js +1 -1
- package/dist/server/prerender-manifest.d.ts +15 -1
- package/dist/server/prerender-manifest.js +29 -1
- package/dist/server/prod-server.d.ts +6 -5
- package/dist/server/prod-server.js +6 -7
- package/dist/server/static-file-cache.js +1 -1
- package/dist/shims/cache.d.ts +1 -1
- package/dist/shims/cdn-cache.d.ts +2 -7
- package/dist/shims/cdn-cache.js +2 -14
- package/dist/shims/form.d.ts +1 -1
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/request-state-types.d.ts +2 -2
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/vite-version.d.ts +3 -13
- package/dist/utils/vite-version.js +38 -30
- package/package.json +31 -13
- package/dist/cloudflare/index.d.ts +0 -3
- package/dist/cloudflare/index.js +0 -3
- package/dist/packages/cloudflare/src/cache/cdn-adapter.runtime.js +0 -102
- package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +0 -126
- package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.js +0 -442
- package/dist/packages/cloudflare/src/deploy-config.js +0 -150
- package/dist/packages/cloudflare/src/deploy-help.js +0 -55
- package/dist/packages/cloudflare/src/deploy.js +0 -272
- package/dist/packages/cloudflare/src/tpr.d.ts +0 -45
- package/dist/packages/cloudflare/src/tpr.js +0 -582
- package/dist/packages/cloudflare/src/utils/cache-control-metadata.js +0 -20
package/dist/index.js
CHANGED
|
@@ -31,14 +31,13 @@ import { createDirectRunner } from "./server/dev-module-runner.js";
|
|
|
31
31
|
import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
32
32
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
33
33
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
34
|
-
import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
34
|
+
import { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
35
35
|
import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
|
|
36
36
|
import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
|
|
37
37
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
38
38
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
39
39
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
40
40
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
41
|
-
import { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine } from "./utils/vite-version.js";
|
|
42
41
|
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
43
42
|
import { mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
44
43
|
import { precompressAssets } from "./build/precompress.js";
|
|
@@ -74,7 +73,7 @@ import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClien
|
|
|
74
73
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
75
74
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
76
75
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter } from "./plugins/sass.js";
|
|
77
|
-
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks,
|
|
76
|
+
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfig, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
78
77
|
import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
79
78
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
80
79
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
@@ -85,12 +84,13 @@ import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeo
|
|
|
85
84
|
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
86
85
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
87
86
|
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
88
|
-
import {
|
|
87
|
+
import { assertSupportedViteVersion, getDepOptimizeNodeEnvOptions, serializeViteDefine } from "./utils/vite-version.js";
|
|
88
|
+
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
89
89
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
90
90
|
import { createRequire } from "node:module";
|
|
91
91
|
import fs from "node:fs";
|
|
92
92
|
import path from "node:path";
|
|
93
|
-
import { loadEnv, parseAst, transformWithOxc } from "vite";
|
|
93
|
+
import { createLogger, loadEnv, parseAst, transformWithOxc } from "vite";
|
|
94
94
|
import { pathToFileURL } from "node:url";
|
|
95
95
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
96
96
|
import commonjs from "vite-plugin-commonjs";
|
|
@@ -159,11 +159,6 @@ function resolveOptionalDependency(projectRoot, specifier) {
|
|
|
159
159
|
} catch {}
|
|
160
160
|
return null;
|
|
161
161
|
}
|
|
162
|
-
async function loadVite7TsconfigPathsPlugin(projectRoot) {
|
|
163
|
-
const resolvedPath = resolveOptionalDependency(projectRoot, "vite-tsconfig-paths");
|
|
164
|
-
if (!resolvedPath) throw new Error("[vinext] Vite 7 requires the optional peer dependency vite-tsconfig-paths for tsconfig path alias support. Install vite-tsconfig-paths or upgrade to Vite 8.");
|
|
165
|
-
return (await import(pathToFileURL(resolvedPath).href)).default();
|
|
166
|
-
}
|
|
167
162
|
function resolveShimModulePath(shimsDir, moduleName) {
|
|
168
163
|
for (const ext of [
|
|
169
164
|
".ts",
|
|
@@ -453,18 +448,98 @@ function suppressOptionalOptimizeDepsWarnings(logger) {
|
|
|
453
448
|
marker[VINEXT_FILTERED_OPTIMIZE_DEPS_WARN] = true;
|
|
454
449
|
}
|
|
455
450
|
const _tsconfigAliasCache = /* @__PURE__ */ new Map();
|
|
451
|
+
/**
|
|
452
|
+
* Order materialized tsconfig path aliases by descending prefix length.
|
|
453
|
+
*
|
|
454
|
+
* TypeScript (and Next.js) match `paths` patterns by longest matched prefix,
|
|
455
|
+
* regardless of declaration order, while Vite's alias plugin picks the first
|
|
456
|
+
* matching entry. Overlapping patterns like `@/*` + `@/public/*` must
|
|
457
|
+
* therefore be materialized longest-first or the general pattern shadows the
|
|
458
|
+
* specific one (`@/public/foo.svg` would resolve into `src/public/`).
|
|
459
|
+
*/
|
|
460
|
+
function sortTsconfigAliasesBySpecificity(aliases) {
|
|
461
|
+
return Object.fromEntries(Object.entries(aliases).sort((a, b) => b[0].length - a[0].length));
|
|
462
|
+
}
|
|
456
463
|
function resolveTsconfigAliases(projectRoot) {
|
|
457
464
|
if (_tsconfigAliasCache.has(projectRoot)) return _tsconfigAliasCache.get(projectRoot);
|
|
458
465
|
let aliases = {};
|
|
459
466
|
for (const name of TSCONFIG_FILES) {
|
|
460
467
|
const candidate = path.join(projectRoot, name);
|
|
461
468
|
if (!fs.existsSync(candidate)) continue;
|
|
462
|
-
aliases = loadTsconfigPathAliases(candidate, projectRoot);
|
|
469
|
+
aliases = sortTsconfigAliasesBySpecificity(loadTsconfigPathAliases(candidate, projectRoot));
|
|
463
470
|
break;
|
|
464
471
|
}
|
|
465
472
|
_tsconfigAliasCache.set(projectRoot, aliases);
|
|
466
473
|
return aliases;
|
|
467
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Stylesheet importer contexts as seen by Vite's internal CSS resolvers.
|
|
477
|
+
*
|
|
478
|
+
* Vite resolves CSS `@import`/`composes`/`url()` specifiers through a
|
|
479
|
+
* dedicated resolver container that only runs the alias plugin plus Vite's
|
|
480
|
+
* own resolver — user plugins never participate. The importer is either the
|
|
481
|
+
* stylesheet's own path (sass, CSS modules `composes`, url() rewriting) or a
|
|
482
|
+
* synthetic `<basedir>/*` (postcss-import, less).
|
|
483
|
+
*/
|
|
484
|
+
const STYLESHEET_IMPORTER_RE = /\.(?:css|scss|sass|less|styl|stylus|pcss|sss)$/i;
|
|
485
|
+
function isStylesheetImporter(importer) {
|
|
486
|
+
if (!importer) return false;
|
|
487
|
+
if (importer.endsWith("/*") || importer.endsWith("\\*")) return true;
|
|
488
|
+
return STYLESHEET_IMPORTER_RE.test(stripViteModuleQuery(importer));
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Alias resolver for tsconfig-derived path aliases that keeps them out of
|
|
492
|
+
* stylesheet resolution.
|
|
493
|
+
*
|
|
494
|
+
* TypeScript `paths` never apply to CSS in Next.js — `@import` specifiers in
|
|
495
|
+
* stylesheets use standard bundler resolution, including package.json
|
|
496
|
+
* `exports` maps. A blind prefix-replacement alias breaks that: with
|
|
497
|
+
* `"@scope/ui/*": ["../../packages/ui/src/*"]` in tsconfig, an
|
|
498
|
+
* `@import "@scope/ui/globals.css"` whose real target is `exports`-mapped
|
|
499
|
+
* gets rewritten to a nonexistent source path and fails with ENOENT.
|
|
500
|
+
*
|
|
501
|
+
* Returning `null` for stylesheet importers makes the alias plugin fall
|
|
502
|
+
* through, so Vite's own resolver handles the original specifier. JS/TS
|
|
503
|
+
* importers keep the default alias behavior (Next.js applies `paths` there,
|
|
504
|
+
* including for `import "@/styles/globals.css"` from a layout), and Vite's
|
|
505
|
+
* glob/dynamic-import transforms — which require blind prefix replacement
|
|
506
|
+
* because their patterns never exist on disk — keep working.
|
|
507
|
+
*/
|
|
508
|
+
const tsconfigAliasCustomResolver = async function(updatedId, importer, options) {
|
|
509
|
+
if (isStylesheetImporter(importer)) return null;
|
|
510
|
+
return await this.resolve(updatedId, importer, {
|
|
511
|
+
...options,
|
|
512
|
+
skipSelf: true
|
|
513
|
+
}) ?? { id: updatedId };
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Convert the merged alias map into Vite alias entries, attaching the
|
|
517
|
+
* stylesheet-scoping resolver to entries that came from tsconfig `paths`.
|
|
518
|
+
* Array order preserves the map's first-match ordering.
|
|
519
|
+
*/
|
|
520
|
+
function buildResolveAliasEntries(aliasMap, tsconfigPathAliases) {
|
|
521
|
+
return Object.entries(aliasMap).map(([find, replacement]) => tsconfigPathAliases[find] === replacement ? {
|
|
522
|
+
find,
|
|
523
|
+
replacement,
|
|
524
|
+
customResolver: tsconfigAliasCustomResolver
|
|
525
|
+
} : {
|
|
526
|
+
find,
|
|
527
|
+
replacement
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
const ALIAS_CUSTOM_RESOLVER_DEPRECATION_RE = /`resolve\.alias` contains an alias with `customResolver` option/;
|
|
531
|
+
const VINEXT_FILTERED_ALIAS_DEPRECATION_WARN = Symbol.for("vinext.filteredAliasDeprecationWarn");
|
|
532
|
+
function suppressAliasCustomResolverDeprecationWarning(logger) {
|
|
533
|
+
const marker = logger;
|
|
534
|
+
if (marker[VINEXT_FILTERED_ALIAS_DEPRECATION_WARN]) return logger;
|
|
535
|
+
const warn = logger.warn.bind(logger);
|
|
536
|
+
logger.warn = (msg, warnOptions) => {
|
|
537
|
+
if (ALIAS_CUSTOM_RESOLVER_DEPRECATION_RE.test(stripAnsi(msg))) return;
|
|
538
|
+
warn(msg, warnOptions);
|
|
539
|
+
};
|
|
540
|
+
marker[VINEXT_FILTERED_ALIAS_DEPRECATION_WARN] = true;
|
|
541
|
+
return logger;
|
|
542
|
+
}
|
|
468
543
|
const VIRTUAL_WORKER_ENTRY = "virtual:vinext-worker-entry";
|
|
469
544
|
const RESOLVED_WORKER_ENTRY = "\0virtual:vinext-worker-entry";
|
|
470
545
|
const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
|
|
@@ -601,22 +676,19 @@ const _reactServerShims = new Map([
|
|
|
601
676
|
["next/error", "error"],
|
|
602
677
|
["next/error.js", "error"]
|
|
603
678
|
]);
|
|
604
|
-
const
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
const appClientCodeSplittingConfig = createClientCodeSplittingConfig(appClientManualChunks);
|
|
608
|
-
function getClientOutputConfigForVite(viteMajorVersion, assetsDir, preserveAppRouteBoundaries = false) {
|
|
609
|
-
const manualChunks = preserveAppRouteBoundaries ? appClientManualChunks : clientManualChunks;
|
|
679
|
+
const clientCodeSplittingConfig = createClientCodeSplittingConfig(createClientManualChunks(_shimsDir));
|
|
680
|
+
const appClientCodeSplittingConfig = createClientCodeSplittingConfig(createClientManualChunks(_shimsDir, true));
|
|
681
|
+
function getClientOutputConfig(assetsDir, preserveAppRouteBoundaries = false) {
|
|
610
682
|
const codeSplitting = preserveAppRouteBoundaries ? appClientCodeSplittingConfig : clientCodeSplittingConfig;
|
|
611
|
-
return
|
|
683
|
+
return {
|
|
612
684
|
...createClientFileNameConfig(assetsDir),
|
|
613
685
|
assetFileNames: createClientAssetFileNames(assetsDir),
|
|
614
686
|
codeSplitting
|
|
615
|
-
}
|
|
687
|
+
};
|
|
616
688
|
}
|
|
617
689
|
function vinext(options = {}) {
|
|
690
|
+
assertSupportedViteVersion();
|
|
618
691
|
const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
|
|
619
|
-
const viteMajorVersion = getViteMajorVersion();
|
|
620
692
|
let root;
|
|
621
693
|
let pagesDir;
|
|
622
694
|
let canonicalPagesDir;
|
|
@@ -774,7 +846,6 @@ function vinext(options = {}) {
|
|
|
774
846
|
return mdxDelegatePromise;
|
|
775
847
|
}
|
|
776
848
|
const plugins = [
|
|
777
|
-
...viteMajorVersion >= 8 ? [] : [loadVite7TsconfigPathsPlugin(earlyBaseDir)],
|
|
778
849
|
createStyledJsxPlugin(earlyBaseDir),
|
|
779
850
|
reactPluginPromise,
|
|
780
851
|
createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
@@ -795,7 +866,7 @@ function vinext(options = {}) {
|
|
|
795
866
|
}
|
|
796
867
|
}
|
|
797
868
|
},
|
|
798
|
-
|
|
869
|
+
{
|
|
799
870
|
name: "vinext:jsx-in-js",
|
|
800
871
|
enforce: "pre",
|
|
801
872
|
transform: {
|
|
@@ -818,7 +889,7 @@ function vinext(options = {}) {
|
|
|
818
889
|
};
|
|
819
890
|
}
|
|
820
891
|
}
|
|
821
|
-
}
|
|
892
|
+
},
|
|
822
893
|
createMiddlewareServerOnlyPlugin({
|
|
823
894
|
getMiddlewarePath: () => middlewarePath,
|
|
824
895
|
getCanonicalMiddlewarePath: () => middlewarePath ? tryRealpathSync(middlewarePath) ?? middlewarePath : null,
|
|
@@ -834,13 +905,20 @@ function vinext(options = {}) {
|
|
|
834
905
|
name: "vinext:config",
|
|
835
906
|
enforce: "pre",
|
|
836
907
|
[VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY]: prerenderConfig,
|
|
908
|
+
[VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY]: {
|
|
909
|
+
appDir: options.appDir,
|
|
910
|
+
disableAppRouter: options.disableAppRouter,
|
|
911
|
+
rscOutDir: options.rscOutDir,
|
|
912
|
+
ssrOutDir: options.ssrOutDir
|
|
913
|
+
},
|
|
914
|
+
[VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY]: options.cache ?? null,
|
|
837
915
|
async config(config, env) {
|
|
838
916
|
isServeCommand = env.command === "serve";
|
|
839
917
|
root = normalizePathSeparators(config.root ?? process.cwd());
|
|
840
|
-
const
|
|
841
|
-
const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === void 0;
|
|
918
|
+
const shouldEnableNativeTsconfigPaths = config.resolve?.tsconfigPaths === void 0;
|
|
842
919
|
const tsconfigPathAliases = resolveTsconfigAliases(root);
|
|
843
920
|
const swcHelpersAlias = resolveSwcHelpersAlias(root);
|
|
921
|
+
if (Object.keys(tsconfigPathAliases).length > 0) config.customLogger = suppressAliasCustomResolverDeprecationWarning(config.customLogger ?? createLogger(config.logLevel, { allowClearScreen: config.clearScreen }));
|
|
844
922
|
const mode = env?.mode ?? "development";
|
|
845
923
|
const dotenvVars = loadEnv(mode, config.envDir ?? root, "");
|
|
846
924
|
for (const [key, value] of Object.entries(dotenvVars)) if (process.env[key] === void 0) process.env[key] = value;
|
|
@@ -1053,7 +1131,7 @@ function vinext(options = {}) {
|
|
|
1053
1131
|
],
|
|
1054
1132
|
assetsDir: clientAssetsDir,
|
|
1055
1133
|
...!isSSR && !hasClientBuildEnvironment ? { assetsInlineLimit: clientAssetsInlineLimit } : {},
|
|
1056
|
-
...withBuildBundlerOptions(
|
|
1134
|
+
...withBuildBundlerOptions({
|
|
1057
1135
|
onwarn: (() => {
|
|
1058
1136
|
const userOnwarn = getBuildBundlerOptions(config.build)?.onwarn;
|
|
1059
1137
|
return (warning, defaultHandler) => {
|
|
@@ -1064,8 +1142,8 @@ function vinext(options = {}) {
|
|
|
1064
1142
|
else defaultHandler(warning);
|
|
1065
1143
|
};
|
|
1066
1144
|
})(),
|
|
1067
|
-
...!isSSR && !isMultiEnv ? { treeshake:
|
|
1068
|
-
...!isSSR && !isMultiEnv ? { output:
|
|
1145
|
+
...!isSSR && !isMultiEnv ? { treeshake: getClientTreeshakeConfig() } : {},
|
|
1146
|
+
...!isSSR && !isMultiEnv ? { output: getClientOutputConfig(clientAssetsDir) } : {}
|
|
1069
1147
|
})
|
|
1070
1148
|
},
|
|
1071
1149
|
server: {
|
|
@@ -1087,13 +1165,13 @@ function vinext(options = {}) {
|
|
|
1087
1165
|
noExternal: true
|
|
1088
1166
|
} },
|
|
1089
1167
|
resolve: {
|
|
1090
|
-
alias: {
|
|
1168
|
+
alias: buildResolveAliasEntries({
|
|
1091
1169
|
...swcHelpersAlias ? { "@swc/helpers/_": swcHelpersAlias } : {},
|
|
1092
1170
|
...tsconfigPathAliases,
|
|
1093
1171
|
...nextConfig.aliases,
|
|
1094
1172
|
...nextShimMap,
|
|
1095
1173
|
"vinext/server/pages-client-assets": _pagesClientAssetsPath
|
|
1096
|
-
},
|
|
1174
|
+
}, tsconfigPathAliases),
|
|
1097
1175
|
dedupe: [
|
|
1098
1176
|
"react",
|
|
1099
1177
|
"react-dom",
|
|
@@ -1102,13 +1180,10 @@ function vinext(options = {}) {
|
|
|
1102
1180
|
],
|
|
1103
1181
|
...shouldEnableNativeTsconfigPaths ? { tsconfigPaths: true } : {}
|
|
1104
1182
|
},
|
|
1105
|
-
|
|
1183
|
+
oxc: {
|
|
1106
1184
|
jsx: { runtime: "automatic" },
|
|
1107
1185
|
typescript: { onlyRemoveTypeImports: false }
|
|
1108
|
-
}
|
|
1109
|
-
jsx: "automatic",
|
|
1110
|
-
tsconfigRaw: { compilerOptions: { verbatimModuleSyntax: false } }
|
|
1111
|
-
} },
|
|
1186
|
+
},
|
|
1112
1187
|
define: defines,
|
|
1113
1188
|
...nextConfig.basePath ? { base: nextConfig.basePath + "/" } : {},
|
|
1114
1189
|
...nextConfig.assetPrefix || nextConfig.deploymentId ? { experimental: { renderBuiltUrl: (filename, context) => renderVinextBuiltUrl(filename, nextConfig.assetPrefix, nextConfig.deploymentId, context.hostType) } } : {},
|
|
@@ -1156,7 +1231,7 @@ function vinext(options = {}) {
|
|
|
1156
1231
|
if (shimBase !== void 0) return resolveShimModulePath(shimsDir, shimBase);
|
|
1157
1232
|
}
|
|
1158
1233
|
};
|
|
1159
|
-
const depOptimizeNodeEnvOptions = getDepOptimizeNodeEnvOptions(
|
|
1234
|
+
const depOptimizeNodeEnvOptions = getDepOptimizeNodeEnvOptions(nodeEnvDefine);
|
|
1160
1235
|
viteConfig.optimizeDeps = {
|
|
1161
1236
|
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, ["@tailwindcss/oxide"]),
|
|
1162
1237
|
...incomingInclude.length > 0 ? { include: incomingInclude } : {},
|
|
@@ -1193,9 +1268,9 @@ function vinext(options = {}) {
|
|
|
1193
1268
|
},
|
|
1194
1269
|
build: {
|
|
1195
1270
|
outDir: options.rscOutDir ?? "dist/server",
|
|
1196
|
-
...withBuildBundlerOptions(
|
|
1271
|
+
...withBuildBundlerOptions({
|
|
1197
1272
|
input: { index: VIRTUAL_RSC_ENTRY },
|
|
1198
|
-
output: createRscFrameworkChunkOutputConfig(
|
|
1273
|
+
output: createRscFrameworkChunkOutputConfig()
|
|
1199
1274
|
})
|
|
1200
1275
|
}
|
|
1201
1276
|
},
|
|
@@ -1215,7 +1290,7 @@ function vinext(options = {}) {
|
|
|
1215
1290
|
},
|
|
1216
1291
|
build: {
|
|
1217
1292
|
outDir: options.ssrOutDir ?? "dist/server/ssr",
|
|
1218
|
-
...withBuildBundlerOptions(
|
|
1293
|
+
...withBuildBundlerOptions({ input: { index: VIRTUAL_APP_SSR_ENTRY } })
|
|
1219
1294
|
}
|
|
1220
1295
|
},
|
|
1221
1296
|
client: {
|
|
@@ -1237,10 +1312,10 @@ function vinext(options = {}) {
|
|
|
1237
1312
|
manifest: true,
|
|
1238
1313
|
...hasPagesDir ? { ssrManifest: true } : {},
|
|
1239
1314
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
1240
|
-
...withBuildBundlerOptions(
|
|
1315
|
+
...withBuildBundlerOptions({
|
|
1241
1316
|
input: appClientInput,
|
|
1242
|
-
output:
|
|
1243
|
-
treeshake:
|
|
1317
|
+
output: getClientOutputConfig(clientAssetsDir, true),
|
|
1318
|
+
treeshake: getClientTreeshakeConfig()
|
|
1244
1319
|
})
|
|
1245
1320
|
}
|
|
1246
1321
|
}
|
|
@@ -1255,10 +1330,10 @@ function vinext(options = {}) {
|
|
|
1255
1330
|
manifest: true,
|
|
1256
1331
|
ssrManifest: true,
|
|
1257
1332
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
1258
|
-
...withBuildBundlerOptions(
|
|
1333
|
+
...withBuildBundlerOptions({
|
|
1259
1334
|
input: { index: VIRTUAL_CLIENT_ENTRY },
|
|
1260
|
-
output:
|
|
1261
|
-
treeshake:
|
|
1335
|
+
output: getClientOutputConfig(clientAssetsDir),
|
|
1336
|
+
treeshake: getClientTreeshakeConfig()
|
|
1262
1337
|
})
|
|
1263
1338
|
}
|
|
1264
1339
|
} };
|
|
@@ -1274,10 +1349,10 @@ function vinext(options = {}) {
|
|
|
1274
1349
|
manifest: true,
|
|
1275
1350
|
ssrManifest: true,
|
|
1276
1351
|
assetsInlineLimit: clientAssetsInlineLimit,
|
|
1277
|
-
...withBuildBundlerOptions(
|
|
1352
|
+
...withBuildBundlerOptions({
|
|
1278
1353
|
input: { index: VIRTUAL_CLIENT_ENTRY },
|
|
1279
|
-
output:
|
|
1280
|
-
treeshake:
|
|
1354
|
+
output: getClientOutputConfig(clientAssetsDir),
|
|
1355
|
+
treeshake: getClientTreeshakeConfig()
|
|
1281
1356
|
})
|
|
1282
1357
|
}
|
|
1283
1358
|
},
|
|
@@ -1298,7 +1373,7 @@ function vinext(options = {}) {
|
|
|
1298
1373
|
},
|
|
1299
1374
|
build: {
|
|
1300
1375
|
outDir: "dist/server",
|
|
1301
|
-
...withBuildBundlerOptions(
|
|
1376
|
+
...withBuildBundlerOptions({
|
|
1302
1377
|
input: { index: VIRTUAL_SERVER_ENTRY },
|
|
1303
1378
|
output: { entryFileNames: "entry.js" }
|
|
1304
1379
|
})
|
|
@@ -1401,91 +1476,94 @@ function vinext(options = {}) {
|
|
|
1401
1476
|
if (reactServerShim !== void 0) return resolveShimModulePath(_shimsDir, this.environment?.name === "rsc" ? `${reactServerShim}.react-server` : reactServerShim);
|
|
1402
1477
|
}
|
|
1403
1478
|
},
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
const
|
|
1416
|
-
|
|
1479
|
+
load: {
|
|
1480
|
+
filter: { id: /virtual:vinext-/ },
|
|
1481
|
+
async handler(id) {
|
|
1482
|
+
if (id === RESOLVED_WORKER_ENTRY) return `export { default } from ${JSON.stringify(hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry")};`;
|
|
1483
|
+
if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1();
|
|
1484
|
+
if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
|
|
1485
|
+
if (id === RESOLVED_PAGES_CLIENT_ASSETS) {
|
|
1486
|
+
const metadata = { clientEntry: DEV_PAGES_CLIENT_ENTRY };
|
|
1487
|
+
const ssrManifest = {};
|
|
1488
|
+
const appFilePath = findFileWithExts(pagesDir, "_app", fileMatcher);
|
|
1489
|
+
const pagesRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1490
|
+
const moduleFilePaths = [...appFilePath ? [appFilePath] : [], ...pagesRoutes.map((route) => route.filePath)];
|
|
1491
|
+
for (const moduleFilePath of moduleFilePaths) {
|
|
1492
|
+
const stylesheetAssets = await collectDevPagesAppStylesheetAssets(root, moduleFilePath, this.resolve.bind(this));
|
|
1493
|
+
if (stylesheetAssets.length > 0) ssrManifest[normalizePathSeparators(moduleFilePath)] = stylesheetAssets;
|
|
1494
|
+
}
|
|
1495
|
+
if (Object.keys(ssrManifest).length > 0) metadata.ssrManifest = ssrManifest;
|
|
1496
|
+
return `export default ${JSON.stringify(metadata)};`;
|
|
1417
1497
|
}
|
|
1418
|
-
if (
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
if (id === RESOLVED_APP_CAPABILITIES && hasAppDir) {
|
|
1482
|
-
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
1483
|
-
return `
|
|
1498
|
+
if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
|
|
1499
|
+
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1500
|
+
const metaRoutes = scanMetadataFiles(appDir);
|
|
1501
|
+
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
1502
|
+
const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
|
|
1503
|
+
const globalNotFoundPath = nextConfig?.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
1504
|
+
rscClassificationManifest = collectRouteClassificationManifest(routes);
|
|
1505
|
+
return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
|
|
1506
|
+
redirects: nextConfig?.redirects,
|
|
1507
|
+
rewrites: nextConfig?.rewrites,
|
|
1508
|
+
headers: nextConfig?.headers,
|
|
1509
|
+
allowedOrigins: nextConfig?.serverActionsAllowedOrigins,
|
|
1510
|
+
allowedDevOrigins: nextConfig?.allowedDevOrigins,
|
|
1511
|
+
bodySizeLimit: nextConfig?.serverActionsBodySizeLimit,
|
|
1512
|
+
bodySizeLimitLabel: nextConfig?.serverActionsBodySizeLimitLabel,
|
|
1513
|
+
htmlLimitedBots: nextConfig?.htmlLimitedBots,
|
|
1514
|
+
clientTraceMetadata: nextConfig?.clientTraceMetadata,
|
|
1515
|
+
assetPrefix: nextConfig?.assetPrefix,
|
|
1516
|
+
expireTime: nextConfig?.expireTime,
|
|
1517
|
+
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
1518
|
+
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
1519
|
+
inlineCss: nextConfig?.inlineCss,
|
|
1520
|
+
globalNotFound: nextConfig?.globalNotFound,
|
|
1521
|
+
cacheComponents: nextConfig?.cacheComponents,
|
|
1522
|
+
prefetchInlining: nextConfig?.prefetchInlining,
|
|
1523
|
+
hasServerActions,
|
|
1524
|
+
i18n: nextConfig?.i18n,
|
|
1525
|
+
imageConfig: {
|
|
1526
|
+
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
1527
|
+
imageSizes: nextConfig?.images?.imageSizes,
|
|
1528
|
+
qualities: nextConfig?.images?.qualities,
|
|
1529
|
+
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
1530
|
+
dangerouslyAllowLocalIP: nextConfig?.images?.dangerouslyAllowLocalIP,
|
|
1531
|
+
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
1532
|
+
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
1533
|
+
},
|
|
1534
|
+
hasPagesDir,
|
|
1535
|
+
publicFiles: scanPublicFileRoutes(root),
|
|
1536
|
+
globalNotFoundPath,
|
|
1537
|
+
draftModeSecret
|
|
1538
|
+
}, instrumentationPath);
|
|
1539
|
+
}
|
|
1540
|
+
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
1541
|
+
if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
|
|
1542
|
+
if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
|
|
1543
|
+
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
|
|
1544
|
+
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
|
|
1545
|
+
const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1546
|
+
const pagesPrefetchRoutes = hasPagesDir ? [...(await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
|
|
1547
|
+
canPrefetchLoadingShell: false,
|
|
1548
|
+
isDynamic: route.isDynamic,
|
|
1549
|
+
patternParts: [...route.patternParts]
|
|
1550
|
+
})), ...(await apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => ({
|
|
1551
|
+
canPrefetchLoadingShell: false,
|
|
1552
|
+
documentOnly: true,
|
|
1553
|
+
isDynamic: route.isDynamic,
|
|
1554
|
+
patternParts: [...route.patternParts]
|
|
1555
|
+
}))] : [];
|
|
1556
|
+
return generateBrowserEntry(graph.routes, graph.routeManifest, pagesPrefetchRoutes, nextConfig.rewrites);
|
|
1557
|
+
}
|
|
1558
|
+
if (id === RESOLVED_APP_CAPABILITIES && hasAppDir) {
|
|
1559
|
+
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
1560
|
+
return `
|
|
1484
1561
|
export const hasServerActions = ${JSON.stringify(hasServerActions)};
|
|
1485
1562
|
export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.stringify(_appBrowserServerActionClientPath)})` : "null"};
|
|
1486
1563
|
`;
|
|
1564
|
+
}
|
|
1565
|
+
if (id.startsWith("\0virtual:vinext-google-fonts?")) return generateGoogleFontsVirtualModule(id, _fontGoogleShimPath);
|
|
1487
1566
|
}
|
|
1488
|
-
if (id.startsWith("\0virtual:vinext-google-fonts?")) return generateGoogleFontsVirtualModule(id, _fontGoogleShimPath);
|
|
1489
1567
|
},
|
|
1490
1568
|
// @vitejs/plugin-rsc runs the RSC environment build in two phases:
|
|
1491
1569
|
renderChunk: {
|
|
@@ -1571,7 +1649,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1571
1649
|
if (!hasAppDir || name !== "rsc" && name !== "ssr") return null;
|
|
1572
1650
|
const output = getBuildBundlerOptions(config.build)?.output;
|
|
1573
1651
|
if (Array.isArray(output) || output?.assetFileNames !== void 0) return null;
|
|
1574
|
-
return { build: { ...withBuildBundlerOptions(
|
|
1652
|
+
return { build: { ...withBuildBundlerOptions({ output: { assetFileNames: createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? "")) } }) } };
|
|
1575
1653
|
}
|
|
1576
1654
|
},
|
|
1577
1655
|
{
|
|
@@ -1621,13 +1699,19 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1621
1699
|
{
|
|
1622
1700
|
name: "vinext:instrumentation-client-inject",
|
|
1623
1701
|
enforce: "pre",
|
|
1624
|
-
resolveId
|
|
1625
|
-
|
|
1626
|
-
|
|
1702
|
+
resolveId: {
|
|
1703
|
+
filter: { id: /^private-next-instrumentation-client$/ },
|
|
1704
|
+
handler(id) {
|
|
1705
|
+
if (id !== VIRTUAL_INSTRUMENTATION_CLIENT) return null;
|
|
1706
|
+
return clientInjectModule !== null ? RESOLVED_INSTRUMENTATION_CLIENT : null;
|
|
1707
|
+
}
|
|
1627
1708
|
},
|
|
1628
|
-
load
|
|
1629
|
-
|
|
1630
|
-
|
|
1709
|
+
load: {
|
|
1710
|
+
filter: { id: /private-next-instrumentation-client\.mjs$/ },
|
|
1711
|
+
handler(id) {
|
|
1712
|
+
if (id !== RESOLVED_INSTRUMENTATION_CLIENT) return null;
|
|
1713
|
+
return clientInjectModule;
|
|
1714
|
+
}
|
|
1631
1715
|
}
|
|
1632
1716
|
},
|
|
1633
1717
|
...options.experimental?.clientReferenceDedup ? [clientReferenceDedupPlugin()] : [],
|
|
@@ -1658,17 +1742,23 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1658
1742
|
{
|
|
1659
1743
|
name: "vinext:react-canary",
|
|
1660
1744
|
enforce: "pre",
|
|
1661
|
-
resolveId
|
|
1662
|
-
|
|
1745
|
+
resolveId: {
|
|
1746
|
+
filter: { id: /^virtual:vinext-react-canary$/ },
|
|
1747
|
+
handler(id) {
|
|
1748
|
+
if (id === "virtual:vinext-react-canary") return "\0virtual:vinext-react-canary";
|
|
1749
|
+
}
|
|
1663
1750
|
},
|
|
1664
|
-
load
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1751
|
+
load: {
|
|
1752
|
+
filter: { id: /^\u0000virtual:vinext-react-canary$/ },
|
|
1753
|
+
handler(id) {
|
|
1754
|
+
if (id === "\0virtual:vinext-react-canary") return [
|
|
1755
|
+
`export * from "react";`,
|
|
1756
|
+
`export { default } from "react";`,
|
|
1757
|
+
`import * as _React from "react";`,
|
|
1758
|
+
`export const ViewTransition = _React.ViewTransition || function ViewTransition({ children }) { return children; };`,
|
|
1759
|
+
`export const addTransitionType = _React.addTransitionType || function addTransitionType() {};`
|
|
1760
|
+
].join("\n");
|
|
1761
|
+
}
|
|
1672
1762
|
},
|
|
1673
1763
|
transform: {
|
|
1674
1764
|
filter: {
|
|
@@ -2408,6 +2498,18 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2408
2498
|
return { define: serverDefines };
|
|
2409
2499
|
}
|
|
2410
2500
|
},
|
|
2501
|
+
{
|
|
2502
|
+
name: "vinext:client-global-define",
|
|
2503
|
+
configEnvironment(name) {
|
|
2504
|
+
if (name !== "client") return null;
|
|
2505
|
+
if (Object.hasOwn(nextConfig.compilerDefine, "global")) return null;
|
|
2506
|
+
const define = { global: "globalThis" };
|
|
2507
|
+
return {
|
|
2508
|
+
define,
|
|
2509
|
+
optimizeDeps: { rolldownOptions: { transform: { define } } }
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
},
|
|
2411
2513
|
{
|
|
2412
2514
|
name: "vinext:image-imports",
|
|
2413
2515
|
enforce: "pre",
|