astro 7.0.0-alpha.0 → 7.0.0-alpha.2
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/components/Code.astro +1 -1
- package/dist/actions/handler.d.ts +32 -0
- package/dist/actions/handler.js +45 -0
- package/dist/actions/runtime/server.js +1 -1
- package/dist/assets/build/generate.js +1 -1
- package/dist/assets/build/remote.d.ts +3 -2
- package/dist/assets/build/remote.js +16 -9
- package/dist/assets/endpoint/dev.js +1 -1
- package/dist/assets/endpoint/generic.js +8 -20
- package/dist/assets/endpoint/loadImage.d.ts +11 -0
- package/dist/assets/endpoint/loadImage.js +19 -0
- package/dist/assets/endpoint/shared.js +7 -2
- package/dist/assets/fonts/config.d.ts +4 -4
- package/dist/assets/fonts/core/optimize-fallbacks.js +38 -13
- package/dist/assets/fonts/definitions.d.ts +2 -2
- package/dist/assets/fonts/infra/system-fallbacks-provider.d.ts +2 -2
- package/dist/assets/fonts/infra/system-fallbacks-provider.js +46 -9
- package/dist/assets/fonts/types.d.ts +1 -0
- package/dist/assets/index.d.ts +1 -0
- package/dist/assets/index.js +2 -0
- package/dist/assets/internal.js +22 -3
- package/dist/assets/services/service.d.ts +1 -1
- package/dist/assets/services/service.js +9 -9
- package/dist/assets/services/sharp.js +53 -18
- package/dist/assets/utils/generateImageStylesCSS.js +26 -6
- package/dist/assets/utils/index.d.ts +1 -0
- package/dist/assets/utils/index.js +2 -0
- package/dist/assets/utils/inferSourceFormat.d.ts +8 -3
- package/dist/assets/utils/inferSourceFormat.js +15 -4
- package/dist/assets/utils/metadata.js +1 -1
- package/dist/assets/utils/redirectValidation.d.ts +48 -0
- package/dist/assets/utils/redirectValidation.js +48 -0
- package/dist/assets/utils/remoteProbe.js +25 -2
- package/dist/assets/utils/vendor/image-size/types/svg.js +1 -1
- package/dist/cli/add/index.js +7 -58
- package/dist/cli/dev/background.d.ts +16 -0
- package/dist/cli/dev/background.js +116 -0
- package/dist/cli/dev/index.js +82 -3
- package/dist/cli/dev/logs.d.ts +6 -0
- package/dist/cli/dev/logs.js +72 -0
- package/dist/cli/dev/status.d.ts +15 -0
- package/dist/cli/dev/status.js +27 -0
- package/dist/cli/dev/stop.d.ts +12 -0
- package/dist/cli/dev/stop.js +43 -0
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/container/index.js +18 -14
- package/dist/content/content-layer.js +16 -11
- package/dist/content/data-store.d.ts +1 -1
- package/dist/content/loaders/types.d.ts +1 -1
- package/dist/content/runtime-assets.d.ts +2 -2
- package/dist/content/runtime.d.ts +1 -1
- package/dist/content/runtime.js +9 -4
- package/dist/content/server-listeners.js +0 -4
- package/dist/content/types-generator.js +5 -1
- package/dist/content/utils.d.ts +1 -1
- package/dist/content/utils.js +1 -1
- package/dist/content/vite-plugin-content-assets.js +1 -0
- package/dist/content/vite-plugin-content-virtual-mod.js +9 -1
- package/dist/core/app/base.d.ts +42 -15
- package/dist/core/app/base.js +151 -375
- package/dist/core/app/dev/app.d.ts +3 -2
- package/dist/core/app/dev/app.js +4 -60
- package/dist/core/app/entrypoints/node.d.ts +1 -1
- package/dist/core/app/entrypoints/node.js +2 -0
- package/dist/core/app/entrypoints/virtual/dev.js +2 -0
- package/dist/core/app/entrypoints/virtual/prod.js +4 -1
- package/dist/core/app/node.d.ts +16 -0
- package/dist/core/app/node.js +59 -13
- package/dist/core/app/prepare-response.d.ts +11 -0
- package/dist/core/app/prepare-response.js +18 -0
- package/dist/core/app/render-options.d.ts +11 -0
- package/dist/core/app/render-options.js +11 -0
- package/dist/core/base-pipeline.d.ts +48 -1
- package/dist/core/base-pipeline.js +63 -8
- package/dist/core/build/app.d.ts +3 -4
- package/dist/core/build/app.js +3 -17
- package/dist/core/build/generate.js +8 -1
- package/dist/core/build/index.d.ts +0 -11
- package/dist/core/build/index.js +0 -3
- package/dist/core/build/internal.d.ts +7 -0
- package/dist/core/build/plugins/plugin-chunk-imports.d.ts +6 -0
- package/dist/core/build/plugins/plugin-chunk-imports.js +29 -17
- package/dist/core/build/plugins/plugin-css.js +40 -1
- package/dist/core/build/plugins/plugin-internals.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +11 -1
- package/dist/core/build/static-build.js +22 -141
- package/dist/core/build/types.d.ts +0 -1
- package/dist/core/build/util.js +8 -1
- package/dist/core/build/vite-build-config.d.ts +28 -0
- package/dist/core/build/vite-build-config.js +165 -0
- package/dist/core/cache/handler.d.ts +29 -0
- package/dist/core/cache/handler.js +81 -0
- package/dist/core/compile/style.js +18 -1
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.js +4 -1
- package/dist/core/config/merge.js +4 -0
- package/dist/core/config/schemas/base.d.ts +25 -13
- package/dist/core/config/schemas/base.js +39 -10
- package/dist/core/config/schemas/relative.d.ts +76 -49
- package/dist/core/config/schemas/relative.js +2 -3
- package/dist/core/config/settings.js +2 -4
- package/dist/core/config/tsconfig.d.ts +24 -9
- package/dist/core/config/tsconfig.js +54 -45
- package/dist/core/config/validate.js +59 -0
- package/dist/core/constants.d.ts +27 -1
- package/dist/core/constants.js +14 -1
- package/dist/core/cookies/cookies.d.ts +7 -2
- package/dist/core/cookies/cookies.js +11 -4
- package/dist/core/cookies/response.d.ts +1 -1
- package/dist/core/cookies/response.js +1 -2
- package/dist/core/create-vite.js +18 -1
- package/dist/core/csp/config.js +17 -5
- package/dist/core/csp/runtime.js +6 -4
- package/dist/core/dev/dev.d.ts +1 -0
- package/dist/core/dev/dev.js +4 -13
- package/dist/core/dev/lockfile.d.ts +54 -0
- package/dist/core/dev/lockfile.js +93 -0
- package/dist/core/errors/build-handler.d.ts +17 -0
- package/dist/core/errors/build-handler.js +22 -0
- package/dist/core/errors/default-handler.d.ts +14 -0
- package/dist/core/errors/default-handler.js +144 -0
- package/dist/core/errors/dev-handler.d.ts +21 -0
- package/dist/core/errors/dev-handler.js +82 -0
- package/dist/core/errors/errors-data.d.ts +43 -38
- package/dist/core/errors/errors-data.js +79 -73
- package/dist/core/errors/handler.d.ts +9 -0
- package/dist/core/errors/handler.js +0 -0
- package/dist/core/errors/zod-error-map.js +30 -1
- package/dist/core/fetch/default-handler.d.ts +17 -0
- package/dist/core/fetch/default-handler.js +45 -0
- package/dist/core/fetch/fetch-state.d.ts +230 -0
- package/dist/core/fetch/fetch-state.js +896 -0
- package/dist/core/fetch/index.d.ts +61 -0
- package/dist/core/fetch/index.js +121 -0
- package/dist/core/fetch/types.d.ts +25 -0
- package/dist/core/fetch/types.js +0 -0
- package/dist/core/fetch/vite-plugin.d.ts +5 -0
- package/dist/core/fetch/vite-plugin.js +76 -0
- package/dist/core/hono/index.d.ts +21 -0
- package/dist/core/hono/index.js +101 -0
- package/dist/core/i18n/domain.d.ts +12 -0
- package/dist/core/i18n/domain.js +66 -0
- package/dist/core/i18n/handler.d.ts +18 -0
- package/dist/core/i18n/handler.js +122 -0
- package/dist/core/logger/core.d.ts +9 -1
- package/dist/core/logger/core.js +17 -1
- package/dist/core/messages/runtime.d.ts +0 -3
- package/dist/core/messages/runtime.js +1 -9
- package/dist/core/middleware/astro-middleware.d.ts +27 -0
- package/dist/core/middleware/astro-middleware.js +51 -0
- package/dist/core/module-loader/vite.js +1 -2
- package/dist/core/pages/handler.d.ts +20 -0
- package/dist/core/pages/handler.js +75 -0
- package/dist/core/preview/index.js +6 -5
- package/dist/core/preview/static-preview-server.js +5 -2
- package/dist/core/redirects/render.d.ts +2 -2
- package/dist/core/redirects/render.js +7 -8
- package/dist/core/render/params-and-props.js +2 -2
- package/dist/core/render/route-cache.d.ts +1 -0
- package/dist/core/render/route-cache.js +4 -4
- package/dist/core/render/slots.js +9 -2
- package/dist/core/rewrites/handler.d.ts +37 -0
- package/dist/core/rewrites/handler.js +67 -0
- package/dist/core/routing/3xx.js +8 -4
- package/dist/core/routing/create-manifest.js +11 -1
- package/dist/core/routing/handler.d.ts +17 -0
- package/dist/core/routing/handler.js +171 -0
- package/dist/core/routing/match.d.ts +0 -7
- package/dist/core/routing/match.js +0 -5
- package/dist/core/routing/parse-route.js +1 -1
- package/dist/core/routing/pattern.js +1 -1
- package/dist/core/routing/rewrite.js +2 -5
- package/dist/core/routing/router.d.ts +8 -0
- package/dist/core/routing/router.js +28 -0
- package/dist/core/routing/trailing-slash-handler.d.ts +18 -0
- package/dist/core/routing/trailing-slash-handler.js +67 -0
- package/dist/core/routing/validation.js +1 -1
- package/dist/core/server-islands/vite-plugin-server-islands.d.ts +6 -1
- package/dist/core/server-islands/vite-plugin-server-islands.js +13 -3
- package/dist/core/session/config.d.ts +1 -1
- package/dist/core/session/drivers.d.ts +1 -1
- package/dist/core/session/handler.d.ts +11 -0
- package/dist/core/session/handler.js +33 -0
- package/dist/core/session/runtime.js +7 -2
- package/dist/core/util/normalized-url.d.ts +10 -0
- package/dist/core/util/normalized-url.js +24 -0
- package/dist/core/util/pathname.d.ts +10 -1
- package/dist/core/util/pathname.js +13 -4
- package/dist/environments.js +1 -1
- package/dist/events/session.d.ts +8 -0
- package/dist/events/session.js +11 -0
- package/dist/i18n/middleware.d.ts +10 -0
- package/dist/i18n/middleware.js +4 -88
- package/dist/i18n/utils.js +2 -2
- package/dist/jsx/rehype.d.ts +1 -1
- package/dist/manifest/virtual-module.js +3 -1
- package/dist/markdown/index.d.ts +4 -0
- package/dist/markdown/index.js +14 -0
- package/dist/prefetch/index.js +12 -7
- package/dist/prerender/utils.js +5 -1
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +9 -0
- package/dist/runtime/server/astro-island.js +57 -20
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/jsx.js +1 -1
- package/dist/runtime/server/render/common.js +10 -4
- package/dist/runtime/server/render/component.js +8 -6
- package/dist/runtime/server/render/head.js +1 -5
- package/dist/runtime/server/render/server-islands.js +2 -1
- package/dist/runtime/server/render/util.js +2 -2
- package/dist/runtime/server/scripts.js +6 -0
- package/dist/runtime/server/transition.d.ts +1 -6
- package/dist/runtime/server/transition.js +0 -8
- package/dist/transitions/events.d.ts +0 -14
- package/dist/transitions/events.js +0 -14
- package/dist/transitions/index.d.ts +0 -1
- package/dist/transitions/index.js +0 -2
- package/dist/transitions/vite-plugin-transitions.js +2 -4
- package/dist/types/public/config.d.ts +96 -14
- package/dist/types/public/content.d.ts +5 -5
- package/dist/types/public/index.d.ts +2 -1
- package/dist/types/public/integrations.d.ts +11 -3
- package/dist/types/public/internal.d.ts +1 -1
- package/dist/types/public/manifest.d.ts +1 -1
- package/dist/virtual-modules/i18n.d.ts +2 -2
- package/dist/virtual-modules/i18n.js +1 -1
- package/dist/vite-plugin-app/app.d.ts +13 -6
- package/dist/vite-plugin-app/app.js +51 -89
- package/dist/vite-plugin-app/createAstroServerApp.d.ts +3 -1
- package/dist/vite-plugin-app/createAstroServerApp.js +4 -3
- package/dist/vite-plugin-astro-server/plugin.js +11 -5
- package/dist/vite-plugin-astro-server/route-guard.d.ts +33 -0
- package/dist/vite-plugin-astro-server/route-guard.js +42 -23
- package/dist/vite-plugin-dev-status/index.d.ts +2 -0
- package/dist/vite-plugin-dev-status/index.js +15 -0
- package/dist/vite-plugin-head/index.js +36 -19
- package/dist/vite-plugin-hmr-reload/index.d.ts +1 -1
- package/dist/vite-plugin-hmr-reload/index.js +23 -1
- package/dist/vite-plugin-integrations-container/index.js +15 -6
- package/dist/vite-plugin-markdown/content-entry-type.js +7 -4
- package/dist/vite-plugin-markdown/images.js +9 -11
- package/dist/vite-plugin-markdown/index.js +12 -11
- package/dist/vite-plugin-utils/index.d.ts +1 -0
- package/dist/vite-plugin-utils/index.js +10 -1
- package/package.json +23 -16
- package/templates/content/types.d.ts +1 -0
- package/types/transitions.d.ts +0 -7
- package/dist/core/render-context.d.ts +0 -77
- package/dist/core/render-context.js +0 -826
|
@@ -92,6 +92,13 @@ export interface BuildInternals {
|
|
|
92
92
|
moduleIds: string[];
|
|
93
93
|
prerender: boolean;
|
|
94
94
|
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Component exports that were rendered during the SSR build.
|
|
97
|
+
* Used by the client build's cssScopeTo recovery to distinguish between
|
|
98
|
+
* CSS that was tree-shaken because the component wasn't rendered in SSR
|
|
99
|
+
* vs CSS that was included in SSR.
|
|
100
|
+
*/
|
|
101
|
+
ssrRenderedExports?: Map<string, Set<string>>;
|
|
95
102
|
}
|
|
96
103
|
/**
|
|
97
104
|
* Creates internal maps used to coordinate the CSS and HTML plugins.
|
|
@@ -6,5 +6,11 @@ import type { StaticBuildOptions } from '../types.js';
|
|
|
6
6
|
* bypass the HTML rendering pipeline and miss skew protection query params.
|
|
7
7
|
*
|
|
8
8
|
* Uses es-module-lexer to reliably parse both static and dynamic imports.
|
|
9
|
+
*
|
|
10
|
+
* This runs in `generateBundle` (not `renderChunk`) so that Vite's CSS plugin
|
|
11
|
+
* can first remove pure-CSS wrapper chunks and replace their imports with
|
|
12
|
+
* `/* empty css * /` comments. If we rewrote imports earlier (in `renderChunk`),
|
|
13
|
+
* the appended query params would break Vite's regex-based CSS chunk cleanup,
|
|
14
|
+
* leaving dangling imports to deleted chunks that 404 at runtime.
|
|
9
15
|
*/
|
|
10
16
|
export declare function pluginChunkImports(options: StaticBuildOptions): VitePlugin | undefined;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { init, parse } from "es-module-lexer";
|
|
2
2
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../../constants.js";
|
|
3
|
+
function getImportSpecifier(code, imp) {
|
|
4
|
+
if (imp.n != null) return imp.n;
|
|
5
|
+
if (imp.d > -1) {
|
|
6
|
+
const raw = code.slice(imp.s, imp.e);
|
|
7
|
+
const quote = raw[0];
|
|
8
|
+
if ((quote === "`" || quote === '"' || quote === "'") && raw.at(-1) === quote) {
|
|
9
|
+
const inner = raw.slice(1, -1);
|
|
10
|
+
if (!inner.includes("${")) return inner;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
3
15
|
function pluginChunkImports(options) {
|
|
4
16
|
const assetQueryParams = options.settings.adapter?.client?.assetQueryParams;
|
|
5
17
|
if (!assetQueryParams || assetQueryParams.toString() === "") {
|
|
@@ -12,25 +24,25 @@ function pluginChunkImports(options) {
|
|
|
12
24
|
applyToEnvironment(environment) {
|
|
13
25
|
return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.client;
|
|
14
26
|
},
|
|
15
|
-
async
|
|
16
|
-
if (!code.includes("./")) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
27
|
+
async generateBundle(_options, bundle) {
|
|
19
28
|
await init;
|
|
20
|
-
const [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
for (const [, chunk] of Object.entries(bundle)) {
|
|
30
|
+
if (chunk.type !== "chunk") continue;
|
|
31
|
+
if (!chunk.code.includes("./")) continue;
|
|
32
|
+
const [imports] = parse(chunk.code);
|
|
33
|
+
const relativeImports = imports.filter((imp) => {
|
|
34
|
+
const name = getImportSpecifier(chunk.code, imp);
|
|
35
|
+
return name != null && /^\.\.?\//.test(name) && /\.(?:js|mjs)$/.test(name);
|
|
36
|
+
});
|
|
37
|
+
if (relativeImports.length === 0) continue;
|
|
38
|
+
let rewritten = chunk.code;
|
|
39
|
+
for (let i = relativeImports.length - 1; i >= 0; i--) {
|
|
40
|
+
const imp = relativeImports[i];
|
|
41
|
+
const insertAt = imp.d > -1 ? imp.e - 1 : imp.e;
|
|
42
|
+
rewritten = rewritten.slice(0, insertAt) + "?" + queryString + rewritten.slice(insertAt);
|
|
43
|
+
}
|
|
44
|
+
chunk.code = rewritten;
|
|
32
45
|
}
|
|
33
|
-
return { code: rewritten, map: null };
|
|
34
46
|
}
|
|
35
47
|
};
|
|
36
48
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isCSSRequest } from "vite";
|
|
2
2
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../../constants.js";
|
|
3
3
|
import { isPropagatedAssetBoundary } from "../../head-propagation/boundary.js";
|
|
4
|
+
import { VIRTUAL_PAGE_RESOLVED_MODULE_ID } from "../../../vite-plugin-pages/const.js";
|
|
4
5
|
import {
|
|
5
6
|
getParentExtendedModuleInfos,
|
|
6
7
|
getParentModuleInfos,
|
|
@@ -18,7 +19,12 @@ function pluginCSS(options, internals) {
|
|
|
18
19
|
function isBuildCssBoundary(id, ctx) {
|
|
19
20
|
if (isPropagatedAssetBoundary(id)) return true;
|
|
20
21
|
const info = ctx.getModuleInfo(id);
|
|
21
|
-
|
|
22
|
+
if (!info || !moduleIsTopLevelPage(info)) return false;
|
|
23
|
+
const allImporters = info.importers.concat(info.dynamicImporters);
|
|
24
|
+
const hasNonVirtualPageImporter = allImporters.some(
|
|
25
|
+
(importer) => !importer.includes(VIRTUAL_PAGE_RESOLVED_MODULE_ID)
|
|
26
|
+
);
|
|
27
|
+
return !hasNonVirtualPageImporter;
|
|
22
28
|
}
|
|
23
29
|
function rollupPluginAstroBuildCSS(options) {
|
|
24
30
|
const { internals, buildOptions } = options;
|
|
@@ -40,10 +46,25 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
40
46
|
internals.cssModuleToChunkIdMap.set(moduleId, chunk.fileName);
|
|
41
47
|
}
|
|
42
48
|
}
|
|
49
|
+
for (const [moduleId, moduleInfo] of Object.entries(chunk.modules || {})) {
|
|
50
|
+
if (moduleInfo.renderedExports.length > 0) {
|
|
51
|
+
const existing = internals.ssrRenderedExports?.get(moduleId);
|
|
52
|
+
if (existing) {
|
|
53
|
+
for (const exp of moduleInfo.renderedExports) {
|
|
54
|
+
existing.add(exp);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
internals.ssrRenderedExports ??= /* @__PURE__ */ new Map();
|
|
58
|
+
internals.ssrRenderedExports.set(moduleId, new Set(moduleInfo.renderedExports));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
43
62
|
}
|
|
44
63
|
}
|
|
45
64
|
const renderedComponentExports = /* @__PURE__ */ new Map();
|
|
46
65
|
const componentToPages = /* @__PURE__ */ new Map();
|
|
66
|
+
const deletedCssAssets = /* @__PURE__ */ new Map();
|
|
67
|
+
const cssScopeToAddedCss = /* @__PURE__ */ new Set();
|
|
47
68
|
if (this.environment?.name === ASTRO_VITE_ENVIRONMENT_NAMES.client) {
|
|
48
69
|
for (const [, item] of Object.entries(bundle)) {
|
|
49
70
|
if (item.type !== "chunk") continue;
|
|
@@ -70,6 +91,9 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
70
91
|
);
|
|
71
92
|
if (allCssInSSR && shouldDeleteCSSChunk(allModules, internals)) {
|
|
72
93
|
for (const cssId of meta.importedCss) {
|
|
94
|
+
if (bundle[cssId]) {
|
|
95
|
+
deletedCssAssets.set(cssId, bundle[cssId]);
|
|
96
|
+
}
|
|
73
97
|
delete bundle[cssId];
|
|
74
98
|
}
|
|
75
99
|
}
|
|
@@ -151,6 +175,14 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
151
175
|
}
|
|
152
176
|
}
|
|
153
177
|
}
|
|
178
|
+
const ssrExports = internals.ssrRenderedExports?.get(scopedToModule);
|
|
179
|
+
if (!ssrExports || !ssrExports.has(scopedToExport)) {
|
|
180
|
+
for (const cssId of meta.importedCss) {
|
|
181
|
+
if (deletedCssAssets.has(cssId)) {
|
|
182
|
+
cssScopeToAddedCss.add(cssId);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
154
186
|
}
|
|
155
187
|
}
|
|
156
188
|
}
|
|
@@ -185,6 +217,13 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
185
217
|
}
|
|
186
218
|
}
|
|
187
219
|
}
|
|
220
|
+
if (cssScopeToAddedCss.size > 0) {
|
|
221
|
+
for (const cssId of cssScopeToAddedCss) {
|
|
222
|
+
if (deletedCssAssets.has(cssId) && !bundle[cssId]) {
|
|
223
|
+
bundle[cssId] = deletedCssAssets.get(cssId);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
188
227
|
}
|
|
189
228
|
};
|
|
190
229
|
const singleCssPlugin = {
|
|
@@ -47,7 +47,8 @@ async function manifestBuildPostHook(options, internals, {
|
|
|
47
47
|
logger: options.logger,
|
|
48
48
|
middlewareEntryPoint: shouldPassMiddlewareEntryPoint ? internals.middlewareEntryPoint : void 0
|
|
49
49
|
});
|
|
50
|
-
const
|
|
50
|
+
const ssrManifest = stripPrerenderedRouteStyles(manifest);
|
|
51
|
+
const code = injectManifest(ssrManifest, ssrManifestChunk.code);
|
|
51
52
|
mutate(ssrManifestChunk.fileName, code, false);
|
|
52
53
|
}
|
|
53
54
|
const prerenderManifestChunk = chunks.find(
|
|
@@ -82,6 +83,15 @@ function injectManifest(manifest, code) {
|
|
|
82
83
|
return JSON.stringify(manifest);
|
|
83
84
|
});
|
|
84
85
|
}
|
|
86
|
+
function stripPrerenderedRouteStyles(manifest) {
|
|
87
|
+
let stripped = false;
|
|
88
|
+
const routes = manifest.routes.map((route) => {
|
|
89
|
+
if (!route.routeData.prerender || route.styles.length === 0) return route;
|
|
90
|
+
stripped = true;
|
|
91
|
+
return { ...route, styles: [] };
|
|
92
|
+
});
|
|
93
|
+
return stripped ? { ...manifest, routes } : manifest;
|
|
94
|
+
}
|
|
85
95
|
async function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
86
96
|
const { settings } = opts;
|
|
87
97
|
const routes = [];
|
|
@@ -10,31 +10,23 @@ import { emptyDir, removeEmptyDirs } from "../../core/fs/index.js";
|
|
|
10
10
|
import { appendForwardSlash, prependForwardSlash } from "../../core/path.js";
|
|
11
11
|
import { runHookBuildSetup } from "../../integrations/hooks.js";
|
|
12
12
|
import { SERIALIZED_MANIFEST_RESOLVED_ID } from "../../manifest/serialized.js";
|
|
13
|
-
import {
|
|
14
|
-
getClientOutputDirectory,
|
|
15
|
-
getPrerenderOutputDirectory,
|
|
16
|
-
getServerOutputDirectory
|
|
17
|
-
} from "../../prerender/utils.js";
|
|
18
|
-
import { VIRTUAL_PAGE_RESOLVED_MODULE_ID } from "../../vite-plugin-pages/const.js";
|
|
13
|
+
import { getPrerenderOutputDirectory, getServerOutputDirectory } from "../../prerender/utils.js";
|
|
19
14
|
import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
20
15
|
import { routeIsRedirect } from "../routing/helpers.js";
|
|
21
|
-
import { getOutDirWithinCwd } from "./common.js";
|
|
22
|
-
import { CHUNKS_PATH } from "./consts.js";
|
|
23
16
|
import { generatePages } from "./generate.js";
|
|
24
17
|
import { trackPageData } from "./internal.js";
|
|
25
18
|
import { getAllBuildPlugins } from "./plugins/index.js";
|
|
26
19
|
import { manifestBuildPostHook } from "./plugins/plugin-manifest.js";
|
|
27
|
-
import {
|
|
28
|
-
isLegacyAdapter,
|
|
29
|
-
LEGACY_SSR_ENTRY_VIRTUAL_MODULE,
|
|
30
|
-
RESOLVED_LEGACY_SSR_ENTRY_VIRTUAL_MODULE
|
|
31
|
-
} from "./plugins/plugin-ssr.js";
|
|
32
20
|
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
|
|
33
|
-
import {
|
|
21
|
+
import { getTimeStat, viteBuildReturnToRolldownOutputs } from "./util.js";
|
|
34
22
|
import { NOOP_MODULE_ID } from "./plugins/plugin-noop.js";
|
|
35
23
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
36
24
|
import { getSSRAssets } from "./internal.js";
|
|
37
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
SERVER_ISLAND_MAP_MARKER,
|
|
27
|
+
hasServerIslands
|
|
28
|
+
} from "../server-islands/vite-plugin-server-islands.js";
|
|
29
|
+
import { createViteBuildConfig } from "./vite-build-config.js";
|
|
38
30
|
const PRERENDER_ENTRY_FILENAME_PREFIX = "prerender-entry";
|
|
39
31
|
function extractRelevantChunks(outputs, prerender) {
|
|
40
32
|
const extracted = [];
|
|
@@ -83,7 +75,6 @@ async function viteBuild(opts) {
|
|
|
83
75
|
async function buildEnvironments(opts, internals) {
|
|
84
76
|
const { allPages, settings, viteConfig } = opts;
|
|
85
77
|
const routes = Object.values(allPages).flatMap((pageData) => pageData.route);
|
|
86
|
-
const legacyAdapter = !settings.adapter || isLegacyAdapter(settings.adapter);
|
|
87
78
|
const buildPlugins = getAllBuildPlugins(internals, opts);
|
|
88
79
|
const flatPlugins = buildPlugins.flat().filter(Boolean);
|
|
89
80
|
const plugins = [...flatPlugins, ...viteConfig.plugins || []];
|
|
@@ -149,69 +140,10 @@ async function buildEnvironments(opts, internals) {
|
|
|
149
140
|
return Object.keys(currentRolldownInput).includes(moduleName);
|
|
150
141
|
}
|
|
151
142
|
}
|
|
152
|
-
const viteBuildConfig = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
target: "esnext",
|
|
157
|
-
// Vite defaults cssMinify to false in SSR by default, but we want to minify it
|
|
158
|
-
// as the CSS generated are used and served to the client.
|
|
159
|
-
cssMinify: viteConfig.build?.minify == null ? true : !!viteConfig.build?.minify,
|
|
160
|
-
...viteConfig.build,
|
|
161
|
-
emptyOutDir: false,
|
|
162
|
-
copyPublicDir: false,
|
|
163
|
-
manifest: false,
|
|
164
|
-
rolldownOptions: {
|
|
165
|
-
...viteConfig.build?.rolldownOptions,
|
|
166
|
-
// Setting as `exports-only` allows us to safely delete inputs that are only used during prerendering
|
|
167
|
-
preserveEntrySignatures: "exports-only",
|
|
168
|
-
...legacyAdapter && settings.buildOutput === "server" ? { input: LEGACY_SSR_ENTRY_VIRTUAL_MODULE } : {},
|
|
169
|
-
output: {
|
|
170
|
-
hoistTransitiveImports: false,
|
|
171
|
-
format: "esm",
|
|
172
|
-
minifyInternalExports: true,
|
|
173
|
-
// Server chunks can't go in the assets (_astro) folder
|
|
174
|
-
// We need to keep these separate
|
|
175
|
-
chunkFileNames(chunkInfo) {
|
|
176
|
-
const { name } = chunkInfo;
|
|
177
|
-
let prefix = CHUNKS_PATH;
|
|
178
|
-
let suffix = "_[hash].mjs";
|
|
179
|
-
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
|
180
|
-
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
|
181
|
-
return [prefix, cleanChunkName(sanitizedName), suffix].join("");
|
|
182
|
-
}
|
|
183
|
-
if (name.startsWith("pages/")) {
|
|
184
|
-
const sanitizedName = name.split(".")[0];
|
|
185
|
-
return [prefix, cleanChunkName(sanitizedName), suffix].join("");
|
|
186
|
-
}
|
|
187
|
-
return [prefix, cleanChunkName(name), suffix].join("");
|
|
188
|
-
},
|
|
189
|
-
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
|
|
190
|
-
...viteConfig.build?.rolldownOptions?.output,
|
|
191
|
-
entryFileNames(chunkInfo) {
|
|
192
|
-
if (chunkInfo.facadeModuleId?.startsWith(VIRTUAL_PAGE_RESOLVED_MODULE_ID)) {
|
|
193
|
-
return makeAstroPageEntryPointFileName(
|
|
194
|
-
VIRTUAL_PAGE_RESOLVED_MODULE_ID,
|
|
195
|
-
chunkInfo.facadeModuleId,
|
|
196
|
-
routes
|
|
197
|
-
);
|
|
198
|
-
} else if (chunkInfo.facadeModuleId === RESOLVED_LEGACY_SSR_ENTRY_VIRTUAL_MODULE || // This catches the case when the adapter uses `entrypointResolution: 'auto'`. When doing so,
|
|
199
|
-
// the adapter must set rolldownOptions.input or Astro sets it from `serverEntrypoint`.
|
|
200
|
-
isRolldownInput(chunkInfo.name) || isRolldownInput(chunkInfo.facadeModuleId)) {
|
|
201
|
-
return opts.settings.config.build.serverEntry;
|
|
202
|
-
} else {
|
|
203
|
-
return "[name].mjs";
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
ssr: true,
|
|
209
|
-
ssrEmitAssets: true,
|
|
210
|
-
// improve build performance
|
|
211
|
-
minify: false,
|
|
212
|
-
modulePreload: { polyfill: false },
|
|
213
|
-
reportCompressedSize: false
|
|
214
|
-
},
|
|
143
|
+
const viteBuildConfig = createViteBuildConfig({
|
|
144
|
+
settings,
|
|
145
|
+
viteConfig,
|
|
146
|
+
routes,
|
|
215
147
|
plugins,
|
|
216
148
|
// Top-level buildApp for framework build orchestration
|
|
217
149
|
// This takes precedence over platform plugin fallbacks (e.g., Cloudflare)
|
|
@@ -225,7 +157,7 @@ async function buildEnvironments(opts, internals) {
|
|
|
225
157
|
const prerenderChunks = extractRelevantChunks(prerenderOutputs, true);
|
|
226
158
|
prerenderOutput = void 0;
|
|
227
159
|
let ssrChunks = [];
|
|
228
|
-
if (settings
|
|
160
|
+
if (needsServerBuild(settings, builder2)) {
|
|
229
161
|
settings.timer.start("SSR build");
|
|
230
162
|
let ssrOutput = await builder2.build(
|
|
231
163
|
builder2.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]
|
|
@@ -244,69 +176,15 @@ async function buildEnvironments(opts, internals) {
|
|
|
244
176
|
internals.clientInput.add(NOOP_MODULE_ID);
|
|
245
177
|
}
|
|
246
178
|
const sortedClientInput = Array.from(internals.clientInput).sort();
|
|
247
|
-
builder2.environments.client.config.build.
|
|
179
|
+
builder2.environments.client.config.build.rolldownOptions.input = sortedClientInput;
|
|
248
180
|
settings.timer.start("Client build");
|
|
249
181
|
await builder2.build(builder2.environments.client);
|
|
250
182
|
settings.timer.end("Client build");
|
|
251
183
|
internals.extractedChunks = [...ssrChunks, ...prerenderChunks];
|
|
252
184
|
}
|
|
253
185
|
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
environments: {
|
|
257
|
-
...viteConfig.environments ?? {},
|
|
258
|
-
[ASTRO_VITE_ENVIRONMENT_NAMES.prerender]: {
|
|
259
|
-
build: {
|
|
260
|
-
emitAssets: true,
|
|
261
|
-
outDir: fileURLToPath(getPrerenderOutputDirectory(settings)),
|
|
262
|
-
rolldownOptions: {
|
|
263
|
-
// Only skip the default prerender entrypoint if an adapter with `entrypointResolution: 'self'` is used
|
|
264
|
-
// AND provides a custom prerenderer. Otherwise, use the default.
|
|
265
|
-
...!legacyAdapter && settings.prerenderer ? {} : { input: "astro/entrypoints/prerender" },
|
|
266
|
-
output: {
|
|
267
|
-
entryFileNames: `${PRERENDER_ENTRY_FILENAME_PREFIX}.[hash].mjs`,
|
|
268
|
-
format: "esm",
|
|
269
|
-
...viteConfig.environments?.prerender?.build?.rolldownOptions?.output
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
ssr: true
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
[ASTRO_VITE_ENVIRONMENT_NAMES.client]: {
|
|
276
|
-
build: {
|
|
277
|
-
emitAssets: true,
|
|
278
|
-
target: "esnext",
|
|
279
|
-
outDir: fileURLToPath(getClientOutputDirectory(settings)),
|
|
280
|
-
copyPublicDir: true,
|
|
281
|
-
sourcemap: viteConfig.environments?.client?.build?.sourcemap ?? false,
|
|
282
|
-
minify: true,
|
|
283
|
-
rolldownOptions: {
|
|
284
|
-
preserveEntrySignatures: "exports-only",
|
|
285
|
-
output: {
|
|
286
|
-
entryFileNames(chunkInfo) {
|
|
287
|
-
return `${settings.config.build.assets}/${cleanChunkName(chunkInfo.name)}.[hash].js`;
|
|
288
|
-
},
|
|
289
|
-
chunkFileNames(chunkInfo) {
|
|
290
|
-
return `${settings.config.build.assets}/${cleanChunkName(chunkInfo.name)}.[hash].js`;
|
|
291
|
-
},
|
|
292
|
-
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
|
|
293
|
-
...viteConfig.environments?.client?.build?.rolldownOptions?.output
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]: {
|
|
299
|
-
build: {
|
|
300
|
-
outDir: fileURLToPath(getServerOutputDirectory(settings)),
|
|
301
|
-
rolldownOptions: {
|
|
302
|
-
output: {
|
|
303
|
-
...viteConfig.environments?.ssr?.build?.rolldownOptions?.output
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
};
|
|
186
|
+
isRolldownInput
|
|
187
|
+
});
|
|
310
188
|
const updatedViteBuildConfig = await runHookBuildSetup({
|
|
311
189
|
config: settings.config,
|
|
312
190
|
pages: internals.pagesByKeys,
|
|
@@ -355,15 +233,12 @@ async function runManifestInjection(opts, internals, chunks, buildPostHooks) {
|
|
|
355
233
|
}
|
|
356
234
|
async function writeMutatedChunks(opts, mutations) {
|
|
357
235
|
const { settings } = opts;
|
|
358
|
-
const config = settings.config;
|
|
359
236
|
for (const [fileName, mutation] of mutations) {
|
|
360
237
|
let root;
|
|
361
238
|
if (mutation.prerender) {
|
|
362
239
|
root = getPrerenderOutputDirectory(settings);
|
|
363
|
-
} else if (settings.buildOutput === "server") {
|
|
364
|
-
root = config.build.server;
|
|
365
240
|
} else {
|
|
366
|
-
root =
|
|
241
|
+
root = getServerOutputDirectory(settings);
|
|
367
242
|
}
|
|
368
243
|
const fullPath = path.join(fileURLToPath(root), fileName);
|
|
369
244
|
const fileURL = pathToFileURL(fullPath);
|
|
@@ -421,6 +296,12 @@ function getClientInput(internals, settings) {
|
|
|
421
296
|
}
|
|
422
297
|
return clientInput;
|
|
423
298
|
}
|
|
299
|
+
function needsServerBuild(settings, builder) {
|
|
300
|
+
if (settings.buildOutput === "server") {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
return hasServerIslands(builder.environments.prerender);
|
|
304
|
+
}
|
|
424
305
|
function makeAstroPageEntryPointFileName(prefix, facadeModuleId, routes) {
|
|
425
306
|
const pageModuleId = facadeModuleId.replace(prefix, "").replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".");
|
|
426
307
|
const route = routes.find((routeData) => routeData.component === pageModuleId);
|
package/dist/core/build/util.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
function getTimeStat(timeStart, timeEnd) {
|
|
2
2
|
const buildTime = timeEnd - timeStart;
|
|
3
|
-
|
|
3
|
+
if (buildTime < 1e3) {
|
|
4
|
+
return `${Math.round(buildTime)}ms`;
|
|
5
|
+
} else if (buildTime < 6e4) {
|
|
6
|
+
return `${(buildTime / 1e3).toFixed(2)}s`;
|
|
7
|
+
}
|
|
8
|
+
const mins = Math.floor(buildTime / 6e4);
|
|
9
|
+
const secs = Math.round(buildTime % 6e4 / 1e3);
|
|
10
|
+
return `${mins}m ${secs}s`;
|
|
4
11
|
}
|
|
5
12
|
function shouldAppendForwardSlash(trailingSlash, buildFormat) {
|
|
6
13
|
switch (trailingSlash) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as vite from 'vite';
|
|
2
|
+
import type { RouteData } from '../../types/public/internal.js';
|
|
3
|
+
import type { AstroSettings } from '../../types/astro.js';
|
|
4
|
+
export interface CreateViteBuildConfigOptions {
|
|
5
|
+
/** The resolved Astro settings. */
|
|
6
|
+
settings: AstroSettings;
|
|
7
|
+
/** The base Vite config produced by createVite(). */
|
|
8
|
+
viteConfig: vite.InlineConfig;
|
|
9
|
+
/** All routes to be built. */
|
|
10
|
+
routes: RouteData[];
|
|
11
|
+
/** Assembled Vite plugins (build plugins + user plugins). */
|
|
12
|
+
plugins: vite.PluginOption[];
|
|
13
|
+
/** The buildApp callback for the Vite builder. */
|
|
14
|
+
builder: vite.BuilderOptions;
|
|
15
|
+
/**
|
|
16
|
+
* A function that checks whether a given module name is a rollup input.
|
|
17
|
+
* Used by entryFileNames to determine the server entry.
|
|
18
|
+
*/
|
|
19
|
+
isRolldownInput: (moduleName: string | undefined) => boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates the Vite InlineConfig used for the multi-environment build.
|
|
23
|
+
*
|
|
24
|
+
* This is a pure config assembly function — it does not execute the build.
|
|
25
|
+
* Extracted from `buildEnvironments()` to enable unit testing of config
|
|
26
|
+
* merging behavior (e.g. user rollup output overrides).
|
|
27
|
+
*/
|
|
28
|
+
export declare function createViteBuildConfig(opts: CreateViteBuildConfigOptions): vite.InlineConfig;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import {
|
|
3
|
+
getClientOutputDirectory,
|
|
4
|
+
getPrerenderOutputDirectory,
|
|
5
|
+
getServerOutputDirectory
|
|
6
|
+
} from "../../prerender/utils.js";
|
|
7
|
+
import { VIRTUAL_PAGE_RESOLVED_MODULE_ID } from "../../vite-plugin-pages/const.js";
|
|
8
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
9
|
+
import { CHUNKS_PATH } from "./consts.js";
|
|
10
|
+
import {
|
|
11
|
+
isLegacyAdapter,
|
|
12
|
+
LEGACY_SSR_ENTRY_VIRTUAL_MODULE,
|
|
13
|
+
RESOLVED_LEGACY_SSR_ENTRY_VIRTUAL_MODULE
|
|
14
|
+
} from "./plugins/plugin-ssr.js";
|
|
15
|
+
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
|
|
16
|
+
import { cleanChunkName } from "./util.js";
|
|
17
|
+
import { makeAstroPageEntryPointFileName } from "./static-build.js";
|
|
18
|
+
const PRERENDER_ENTRY_FILENAME_PREFIX = "prerender-entry";
|
|
19
|
+
function createViteBuildConfig(opts) {
|
|
20
|
+
const { settings, viteConfig, routes, plugins, builder, isRolldownInput } = opts;
|
|
21
|
+
const legacyAdapter = !settings.adapter || isLegacyAdapter(settings.adapter);
|
|
22
|
+
return {
|
|
23
|
+
...viteConfig,
|
|
24
|
+
logLevel: viteConfig.logLevel ?? "error",
|
|
25
|
+
build: {
|
|
26
|
+
target: "esnext",
|
|
27
|
+
// Vite defaults cssMinify to false in SSR by default, but we want to minify it
|
|
28
|
+
// as the CSS generated are used and served to the client.
|
|
29
|
+
cssMinify: viteConfig.build?.minify == null ? true : !!viteConfig.build?.minify,
|
|
30
|
+
...viteConfig.build,
|
|
31
|
+
emptyOutDir: false,
|
|
32
|
+
copyPublicDir: false,
|
|
33
|
+
manifest: false,
|
|
34
|
+
rolldownOptions: {
|
|
35
|
+
...viteConfig.build?.rolldownOptions,
|
|
36
|
+
// Setting as `exports-only` allows us to safely delete inputs that are only used during prerendering
|
|
37
|
+
preserveEntrySignatures: "exports-only",
|
|
38
|
+
...legacyAdapter && settings.buildOutput === "server" ? { input: LEGACY_SSR_ENTRY_VIRTUAL_MODULE } : {},
|
|
39
|
+
output: {
|
|
40
|
+
hoistTransitiveImports: false,
|
|
41
|
+
format: "esm",
|
|
42
|
+
minifyInternalExports: true,
|
|
43
|
+
// Server chunks can't go in the assets (_astro) folder
|
|
44
|
+
// We need to keep these separate
|
|
45
|
+
chunkFileNames(chunkInfo) {
|
|
46
|
+
const { name } = chunkInfo;
|
|
47
|
+
let prefix = CHUNKS_PATH;
|
|
48
|
+
let suffix = "_[hash].mjs";
|
|
49
|
+
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
|
50
|
+
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
|
51
|
+
return [prefix, cleanChunkName(sanitizedName), suffix].join("");
|
|
52
|
+
}
|
|
53
|
+
if (name.startsWith("pages/")) {
|
|
54
|
+
const sanitizedName = name.split(".")[0];
|
|
55
|
+
return [prefix, cleanChunkName(sanitizedName), suffix].join("");
|
|
56
|
+
}
|
|
57
|
+
return [prefix, cleanChunkName(name), suffix].join("");
|
|
58
|
+
},
|
|
59
|
+
assetFileNames(assetInfo) {
|
|
60
|
+
const name = assetInfo.names?.[0] ?? "";
|
|
61
|
+
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
|
62
|
+
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
|
63
|
+
return `${settings.config.build.assets}/${sanitizedName}.[hash][extname]`;
|
|
64
|
+
}
|
|
65
|
+
return `${settings.config.build.assets}/[name].[hash][extname]`;
|
|
66
|
+
},
|
|
67
|
+
...viteConfig.build?.rolldownOptions?.output,
|
|
68
|
+
entryFileNames(chunkInfo) {
|
|
69
|
+
if (chunkInfo.facadeModuleId?.startsWith(VIRTUAL_PAGE_RESOLVED_MODULE_ID)) {
|
|
70
|
+
return makeAstroPageEntryPointFileName(
|
|
71
|
+
VIRTUAL_PAGE_RESOLVED_MODULE_ID,
|
|
72
|
+
chunkInfo.facadeModuleId,
|
|
73
|
+
routes
|
|
74
|
+
);
|
|
75
|
+
} else if (chunkInfo.facadeModuleId === RESOLVED_LEGACY_SSR_ENTRY_VIRTUAL_MODULE || // This catches the case when the adapter uses `entrypointResolution: 'auto'`. When doing so,
|
|
76
|
+
// the adapter must set rolldownOptions.input or Astro sets it from `serverEntrypoint`.
|
|
77
|
+
isRolldownInput(chunkInfo.name) || isRolldownInput(chunkInfo.facadeModuleId)) {
|
|
78
|
+
return settings.config.build.serverEntry;
|
|
79
|
+
} else {
|
|
80
|
+
return "[name].mjs";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
ssr: true,
|
|
86
|
+
ssrEmitAssets: true,
|
|
87
|
+
// improve build performance
|
|
88
|
+
minify: false,
|
|
89
|
+
modulePreload: { polyfill: false },
|
|
90
|
+
reportCompressedSize: false
|
|
91
|
+
},
|
|
92
|
+
plugins,
|
|
93
|
+
builder,
|
|
94
|
+
envPrefix: viteConfig.envPrefix ?? "PUBLIC_",
|
|
95
|
+
base: settings.config.base,
|
|
96
|
+
environments: {
|
|
97
|
+
...viteConfig.environments ?? {},
|
|
98
|
+
[ASTRO_VITE_ENVIRONMENT_NAMES.prerender]: {
|
|
99
|
+
build: {
|
|
100
|
+
emitAssets: true,
|
|
101
|
+
outDir: fileURLToPath(getPrerenderOutputDirectory(settings)),
|
|
102
|
+
rolldownOptions: {
|
|
103
|
+
// Only skip the default prerender entrypoint if an adapter with `entrypointResolution: 'self'` is used
|
|
104
|
+
// AND provides a custom prerenderer. Otherwise, use the default.
|
|
105
|
+
...!legacyAdapter && settings.prerenderer ? {} : { input: "astro/entrypoints/prerender" },
|
|
106
|
+
output: {
|
|
107
|
+
entryFileNames: `${PRERENDER_ENTRY_FILENAME_PREFIX}.[hash].mjs`,
|
|
108
|
+
format: "esm",
|
|
109
|
+
...viteConfig.environments?.prerender?.build?.rolldownOptions?.output
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
ssr: true
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
[ASTRO_VITE_ENVIRONMENT_NAMES.client]: {
|
|
116
|
+
build: {
|
|
117
|
+
emitAssets: true,
|
|
118
|
+
target: "esnext",
|
|
119
|
+
outDir: fileURLToPath(getClientOutputDirectory(settings)),
|
|
120
|
+
copyPublicDir: true,
|
|
121
|
+
sourcemap: viteConfig.environments?.client?.build?.sourcemap ?? viteConfig.build?.sourcemap ?? false,
|
|
122
|
+
minify: viteConfig.environments?.client?.build?.minify ?? viteConfig.build?.minify ?? true,
|
|
123
|
+
rolldownOptions: {
|
|
124
|
+
preserveEntrySignatures: "exports-only",
|
|
125
|
+
output: {
|
|
126
|
+
// Inherit top-level rolldown output options (e.g. compact) as a
|
|
127
|
+
// base, then layer Astro defaults on top so that Astro's
|
|
128
|
+
// naming functions are preserved unless explicitly overridden
|
|
129
|
+
// via the environment-specific config.
|
|
130
|
+
...viteConfig.build?.rolldownOptions?.output,
|
|
131
|
+
entryFileNames(chunkInfo) {
|
|
132
|
+
return `${settings.config.build.assets}/${cleanChunkName(chunkInfo.name)}.[hash].js`;
|
|
133
|
+
},
|
|
134
|
+
chunkFileNames(chunkInfo) {
|
|
135
|
+
return `${settings.config.build.assets}/${cleanChunkName(chunkInfo.name)}.[hash].js`;
|
|
136
|
+
},
|
|
137
|
+
assetFileNames(assetInfo) {
|
|
138
|
+
const name = assetInfo.names?.[0] ?? "";
|
|
139
|
+
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
|
140
|
+
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
|
141
|
+
return `${settings.config.build.assets}/${sanitizedName}.[hash][extname]`;
|
|
142
|
+
}
|
|
143
|
+
return `${settings.config.build.assets}/[name].[hash][extname]`;
|
|
144
|
+
},
|
|
145
|
+
...viteConfig.environments?.client?.build?.rolldownOptions?.output
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]: {
|
|
151
|
+
build: {
|
|
152
|
+
outDir: fileURLToPath(getServerOutputDirectory(settings)),
|
|
153
|
+
rolldownOptions: {
|
|
154
|
+
output: {
|
|
155
|
+
...viteConfig.environments?.ssr?.build?.rolldownOptions?.output
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
createViteBuildConfig
|
|
165
|
+
};
|