astro 4.3.7 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Image.astro +4 -0
- package/components/Picture.astro +4 -0
- package/dist/@types/astro.d.ts +42 -42
- package/dist/assets/build/generate.d.ts +1 -1
- package/dist/assets/build/generate.js +1 -2
- package/dist/assets/internal.js +14 -0
- package/dist/assets/types.d.ts +23 -2
- package/dist/assets/utils/metadata.js +3 -3
- package/dist/assets/utils/remoteProbe.d.ts +2 -0
- package/dist/assets/utils/remoteProbe.js +35 -0
- package/dist/assets/utils/vendor/image-size/detector.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/detector.js +24 -0
- package/dist/assets/utils/vendor/image-size/lookup.d.ts +10 -0
- package/dist/assets/utils/vendor/image-size/lookup.js +26 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/cur.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/cur.js +17 -0
- package/dist/assets/utils/vendor/image-size/types/dds.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/dds.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/gif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/gif.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/heif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/heif.js +53 -0
- package/dist/assets/utils/vendor/image-size/types/icns.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/icns.js +85 -0
- package/dist/assets/utils/vendor/image-size/types/ico.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ico.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -0
- package/dist/assets/utils/vendor/image-size/types/index.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/interface.d.ts +13 -0
- package/dist/assets/utils/vendor/image-size/types/interface.js +0 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.js +25 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.js +97 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.js +19 -0
- package/dist/assets/utils/vendor/image-size/types/png.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/png.js +34 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.js +69 -0
- package/dist/assets/utils/vendor/image-size/types/psd.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/psd.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/svg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/svg.js +94 -0
- package/dist/assets/utils/vendor/image-size/types/tga.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tga.js +15 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.js +66 -0
- package/dist/assets/utils/vendor/image-size/types/utils.d.ts +15 -0
- package/dist/assets/utils/vendor/image-size/types/utils.js +60 -0
- package/dist/assets/utils/vendor/image-size/types/webp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/webp.js +52 -0
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +10 -3
- package/dist/cli/db/index.js +2 -0
- package/dist/cli/info/index.js +2 -0
- package/dist/cli/preferences/index.js +2 -0
- package/dist/content/runtime.js +3 -1
- package/dist/content/types-generator.js +7 -27
- package/dist/core/app/index.js +39 -122
- package/dist/core/app/pipeline.d.ts +7 -0
- package/dist/core/app/pipeline.js +39 -0
- package/dist/core/base-pipeline.d.ts +59 -0
- package/dist/core/base-pipeline.js +27 -0
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +39 -109
- package/dist/core/build/index.js +0 -4
- package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
- package/dist/core/build/pipeline.js +180 -0
- package/dist/core/build/plugins/plugin-css.js +6 -5
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +6 -5
- package/dist/core/build/plugins/util.d.ts +2 -1
- package/dist/core/build/plugins/util.js +12 -1
- package/dist/core/build/types.d.ts +0 -2
- package/dist/core/constants.d.ts +10 -1
- package/dist/core/constants.js +14 -4
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -1
- package/dist/core/endpoint/index.d.ts +5 -4
- package/dist/core/endpoint/index.js +7 -34
- package/dist/core/errors/errors-data.d.ts +16 -3
- package/dist/core/errors/errors-data.js +9 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +1 -1
- package/dist/core/middleware/callMiddleware.js +2 -9
- package/dist/core/middleware/index.d.ts +2 -2
- package/dist/core/middleware/index.js +74 -9
- package/dist/core/module-loader/vite.js +4 -4
- package/dist/core/preview/index.js +2 -0
- package/dist/core/preview/static-preview-server.js +1 -7
- package/dist/core/redirects/helpers.d.ts +1 -3
- package/dist/core/redirects/helpers.js +0 -29
- package/dist/core/redirects/index.d.ts +2 -1
- package/dist/core/redirects/index.js +3 -3
- package/dist/core/redirects/render.d.ts +2 -0
- package/dist/core/redirects/render.js +33 -0
- package/dist/core/render/index.d.ts +7 -13
- package/dist/core/render/index.js +7 -7
- package/dist/core/render/params-and-props.d.ts +8 -3
- package/dist/core/render/params-and-props.js +24 -16
- package/dist/core/render/result.d.ts +6 -5
- package/dist/core/render/result.js +3 -4
- package/dist/core/render-context.d.ts +32 -0
- package/dist/core/render-context.js +219 -0
- package/dist/core/routing/index.d.ts +0 -1
- package/dist/core/routing/index.js +0 -2
- package/dist/core/routing/manifest/create.js +11 -27
- package/dist/core/routing/params.d.ts +1 -7
- package/dist/core/routing/params.js +0 -15
- package/dist/core/sync/index.js +3 -3
- package/dist/i18n/middleware.d.ts +0 -5
- package/dist/i18n/middleware.js +61 -69
- package/dist/i18n/utils.d.ts +25 -0
- package/dist/{core/render/context.js → i18n/utils.js} +3 -49
- package/dist/prerender/routing.d.ts +1 -1
- package/dist/prerender/routing.js +20 -21
- package/dist/runtime/client/dev-toolbar/apps/astro.js +14 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +115 -6
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.d.ts +2 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.js +110 -0
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +6 -1
- package/dist/runtime/client/dev-toolbar/ui-library/card.js +1 -1
- package/dist/runtime/server/astro-island.js +10 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +7 -0
- package/dist/runtime/server/astro-island.prebuilt-dev.js +4 -0
- 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/endpoint.js +2 -2
- package/dist/runtime/server/render/astro/render.d.ts +1 -0
- package/dist/runtime/server/render/astro/render.js +81 -2
- package/dist/runtime/server/render/component.js +6 -0
- package/dist/runtime/server/render/page.js +15 -2
- package/dist/runtime/server/render/util.d.ts +7 -0
- package/dist/runtime/server/render/util.js +15 -0
- package/dist/runtime/server/scripts.js +2 -4
- package/dist/runtime/server/transition.js +14 -1
- package/dist/vite-plugin-astro/hmr.d.ts +1 -0
- package/dist/vite-plugin-astro/hmr.js +7 -4
- package/dist/vite-plugin-astro-server/error.d.ts +2 -2
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +0 -6
- package/dist/vite-plugin-astro-server/index.js +0 -19
- package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
- package/dist/vite-plugin-astro-server/pipeline.js +117 -0
- package/dist/vite-plugin-astro-server/plugin.js +3 -4
- package/dist/vite-plugin-astro-server/request.d.ts +3 -4
- package/dist/vite-plugin-astro-server/request.js +6 -9
- package/dist/vite-plugin-astro-server/route.d.ts +3 -4
- package/dist/vite-plugin-astro-server/route.js +34 -162
- package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
- package/package.json +7 -12
- package/dist/core/app/ssrPipeline.d.ts +0 -3
- package/dist/core/app/ssrPipeline.js +0 -6
- package/dist/core/build/buildPipeline.js +0 -150
- package/dist/core/pipeline.d.ts +0 -39
- package/dist/core/pipeline.js +0 -107
- package/dist/core/render/context.d.ts +0 -52
- package/dist/core/render/core.d.ts +0 -10
- package/dist/core/render/core.js +0 -65
- package/dist/core/render/environment.d.ts +0 -34
- package/dist/core/render/environment.js +0 -6
- package/dist/runtime/server/consts.d.ts +0 -1
- package/dist/runtime/server/consts.js +0 -4
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
- package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
|
@@ -16,29 +16,20 @@ import {
|
|
|
16
16
|
removeLeadingForwardSlash,
|
|
17
17
|
removeTrailingForwardSlash
|
|
18
18
|
} from "../../core/path.js";
|
|
19
|
-
import { createI18nMiddleware, i18nPipelineHook } from "../../i18n/middleware.js";
|
|
20
19
|
import { runHookBuildGenerated } from "../../integrations/index.js";
|
|
21
20
|
import { getOutputDirectory, isServerLikeOutput } from "../../prerender/utils.js";
|
|
22
|
-
import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
23
21
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
24
|
-
import { sequence } from "../middleware/index.js";
|
|
25
22
|
import { routeIsFallback } from "../redirects/helpers.js";
|
|
26
23
|
import {
|
|
27
24
|
RedirectSinglePageBuiltModule,
|
|
28
25
|
getRedirectLocationOrThrow,
|
|
29
26
|
routeIsRedirect
|
|
30
27
|
} from "../redirects/index.js";
|
|
31
|
-
import { createRenderContext } from "../render/index.js";
|
|
32
28
|
import { callGetStaticPaths } from "../render/route-cache.js";
|
|
33
|
-
import {
|
|
34
|
-
createAssetLink,
|
|
35
|
-
createModuleScriptsSet,
|
|
36
|
-
createStylesheetElementSet
|
|
37
|
-
} from "../render/ssr-element.js";
|
|
38
29
|
import { createRequest } from "../request.js";
|
|
39
30
|
import { matchRoute } from "../routing/match.js";
|
|
40
31
|
import { getOutputFilename } from "../util.js";
|
|
41
|
-
import { BuildPipeline } from "./
|
|
32
|
+
import { BuildPipeline } from "./pipeline.js";
|
|
42
33
|
import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
|
|
43
34
|
import {
|
|
44
35
|
cssOrder,
|
|
@@ -48,6 +39,7 @@ import {
|
|
|
48
39
|
} from "./internal.js";
|
|
49
40
|
import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
|
|
50
41
|
import { NoPrerenderedRoutesWithDomains } from "../errors/errors-data.js";
|
|
42
|
+
import { RenderContext } from "../render-context.js";
|
|
51
43
|
function createEntryURL(filePath, outFolder) {
|
|
52
44
|
return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
|
|
53
45
|
}
|
|
@@ -95,14 +87,14 @@ function chunkIsPage(settings, output, internals) {
|
|
|
95
87
|
}
|
|
96
88
|
return false;
|
|
97
89
|
}
|
|
98
|
-
async function generatePages(
|
|
90
|
+
async function generatePages(options, internals) {
|
|
99
91
|
const generatePagesTimer = performance.now();
|
|
100
|
-
const ssr = isServerLikeOutput(
|
|
92
|
+
const ssr = isServerLikeOutput(options.settings.config);
|
|
101
93
|
let manifest;
|
|
102
94
|
if (ssr) {
|
|
103
|
-
manifest = await BuildPipeline.retrieveManifest(
|
|
95
|
+
manifest = await BuildPipeline.retrieveManifest(options, internals);
|
|
104
96
|
} else {
|
|
105
|
-
const baseDirectory = getOutputDirectory(
|
|
97
|
+
const baseDirectory = getOutputDirectory(options.settings.config);
|
|
106
98
|
const renderersEntryUrl = new URL("renderers.mjs", baseDirectory);
|
|
107
99
|
const renderers = await import(renderersEntryUrl.toString());
|
|
108
100
|
let middleware = (_, next) => next();
|
|
@@ -113,15 +105,15 @@ async function generatePages(opts, internals) {
|
|
|
113
105
|
} catch {
|
|
114
106
|
}
|
|
115
107
|
manifest = createBuildManifest(
|
|
116
|
-
|
|
108
|
+
options.settings,
|
|
117
109
|
internals,
|
|
118
110
|
renderers.renderers,
|
|
119
111
|
middleware
|
|
120
112
|
);
|
|
121
113
|
}
|
|
122
|
-
const pipeline =
|
|
123
|
-
const
|
|
124
|
-
const
|
|
114
|
+
const pipeline = BuildPipeline.create({ internals, manifest, options });
|
|
115
|
+
const { config, logger } = pipeline;
|
|
116
|
+
const outFolder = ssr ? options.settings.config.build.server : getOutDirWithinCwd(options.settings.config.outDir);
|
|
125
117
|
if (ssr && !hasPrerenderedPages(internals)) {
|
|
126
118
|
delete globalThis?.astroAsset?.addStaticImage;
|
|
127
119
|
return;
|
|
@@ -131,7 +123,6 @@ async function generatePages(opts, internals) {
|
|
|
131
123
|
${bgGreen(black(` ${verb} static routes `))}`);
|
|
132
124
|
const builtPaths = /* @__PURE__ */ new Set();
|
|
133
125
|
const pagesToGenerate = pipeline.retrieveRoutesToGenerate();
|
|
134
|
-
const config = pipeline.getConfig();
|
|
135
126
|
if (ssr) {
|
|
136
127
|
for (const [pageData, filePath] of pagesToGenerate) {
|
|
137
128
|
if (pageData.route.prerender) {
|
|
@@ -143,7 +134,7 @@ ${bgGreen(black(` ${verb} static routes `))}`);
|
|
|
143
134
|
}
|
|
144
135
|
const ssrEntryURLPage = createEntryURL(filePath, outFolder);
|
|
145
136
|
const ssrEntryPage = await import(ssrEntryURLPage.toString());
|
|
146
|
-
if (
|
|
137
|
+
if (options.settings.adapter?.adapterFeatures?.functionPerRoute) {
|
|
147
138
|
const ssrEntry = ssrEntryPage?.pageModule;
|
|
148
139
|
if (ssrEntry) {
|
|
149
140
|
await generatePage(pageData, ssrEntry, builtPaths, pipeline);
|
|
@@ -183,11 +174,11 @@ ${bgGreen(black(` ${verb} static routes `))}`);
|
|
|
183
174
|
logger.info("SKIP_FORMAT", `${bgGreen(black(` generating optimized images `))}`);
|
|
184
175
|
const totalCount = Array.from(staticImageList.values()).map((x) => x.transforms.size).reduce((a, b) => a + b, 0);
|
|
185
176
|
const cpuCount = os.cpus().length;
|
|
186
|
-
const
|
|
177
|
+
const assetsCreationpipeline = await prepareAssetsGenerationEnv(pipeline, totalCount);
|
|
187
178
|
const queue = new PQueue({ concurrency: Math.max(cpuCount, 1) });
|
|
188
179
|
const assetsTimer = performance.now();
|
|
189
180
|
for (const [originalPath, transforms] of staticImageList) {
|
|
190
|
-
await generateImagesForPath(originalPath, transforms,
|
|
181
|
+
await generateImagesForPath(originalPath, transforms, assetsCreationpipeline, queue);
|
|
191
182
|
}
|
|
192
183
|
await queue.onIdle();
|
|
193
184
|
const assetsTimeEnd = performance.now();
|
|
@@ -195,33 +186,15 @@ ${bgGreen(black(` ${verb} static routes `))}`);
|
|
|
195
186
|
`));
|
|
196
187
|
delete globalThis?.astroAsset?.addStaticImage;
|
|
197
188
|
}
|
|
198
|
-
await runHookBuildGenerated({
|
|
199
|
-
config: opts.settings.config,
|
|
200
|
-
logger: pipeline.getLogger()
|
|
201
|
-
});
|
|
189
|
+
await runHookBuildGenerated({ config, logger });
|
|
202
190
|
}
|
|
203
191
|
async function generatePage(pageData, ssrEntry, builtPaths, pipeline) {
|
|
204
|
-
const logger = pipeline
|
|
205
|
-
const config = pipeline.getConfig();
|
|
206
|
-
const manifest = pipeline.getManifest();
|
|
192
|
+
const { config, internals, logger } = pipeline;
|
|
207
193
|
const pageModulePromise = ssrEntry.page;
|
|
208
|
-
const
|
|
209
|
-
const pageInfo = getPageDataByComponent(pipeline.getInternals(), pageData.route.component);
|
|
194
|
+
const pageInfo = getPageDataByComponent(internals, pageData.route.component);
|
|
210
195
|
const styles = pageData.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
|
|
211
196
|
const linkIds = [];
|
|
212
197
|
const scripts = pageInfo?.hoistedScript ?? null;
|
|
213
|
-
const i18nMiddleware = createI18nMiddleware(
|
|
214
|
-
manifest.i18n,
|
|
215
|
-
manifest.base,
|
|
216
|
-
manifest.trailingSlash,
|
|
217
|
-
manifest.buildFormat
|
|
218
|
-
);
|
|
219
|
-
if (config.i18n && i18nMiddleware) {
|
|
220
|
-
pipeline.setMiddlewareFunction(sequence(i18nMiddleware, onRequest));
|
|
221
|
-
pipeline.onBeforeRenderRoute(i18nPipelineHook);
|
|
222
|
-
} else {
|
|
223
|
-
pipeline.setMiddlewareFunction(onRequest);
|
|
224
|
-
}
|
|
225
198
|
if (!pageModulePromise) {
|
|
226
199
|
throw new Error(
|
|
227
200
|
`Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.`
|
|
@@ -243,8 +216,8 @@ async function generatePage(pageData, ssrEntry, builtPaths, pipeline) {
|
|
|
243
216
|
let prevTimeEnd = timeStart;
|
|
244
217
|
for (let i = 0; i < paths.length; i++) {
|
|
245
218
|
const path = paths[i];
|
|
246
|
-
pipeline.
|
|
247
|
-
const filePath = getOutputFilename(
|
|
219
|
+
pipeline.logger.debug("build", `Generating: ${path}`);
|
|
220
|
+
const filePath = getOutputFilename(config, path, pageData.route.type);
|
|
248
221
|
const lineIcon = i === paths.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
249
222
|
logger.info(null, ` ${blue(lineIcon)} ${dim(filePath)}`, false);
|
|
250
223
|
await generatePath(path, pipeline, generationOptions, route);
|
|
@@ -263,8 +236,7 @@ function* eachRouteInRouteData(data) {
|
|
|
263
236
|
}
|
|
264
237
|
}
|
|
265
238
|
async function getPathsForRoute(route, mod, pipeline, builtPaths) {
|
|
266
|
-
const
|
|
267
|
-
const logger = pipeline.getLogger();
|
|
239
|
+
const { logger, options, routeCache, serverLike } = pipeline;
|
|
268
240
|
let paths = [];
|
|
269
241
|
if (route.pathname) {
|
|
270
242
|
paths.push(route.pathname);
|
|
@@ -279,9 +251,9 @@ async function getPathsForRoute(route, mod, pipeline, builtPaths) {
|
|
|
279
251
|
const staticPaths = await callGetStaticPaths({
|
|
280
252
|
mod,
|
|
281
253
|
route,
|
|
282
|
-
routeCache
|
|
254
|
+
routeCache,
|
|
283
255
|
logger,
|
|
284
|
-
ssr:
|
|
256
|
+
ssr: serverLike
|
|
285
257
|
}).catch((err) => {
|
|
286
258
|
logger.debug("build", `\u251C\u2500\u2500 ${bold(red("\u2717"))} ${route.component}`);
|
|
287
259
|
throw err;
|
|
@@ -304,7 +276,7 @@ async function getPathsForRoute(route, mod, pipeline, builtPaths) {
|
|
|
304
276
|
if (!builtPaths.has(removeTrailingForwardSlash(staticPath))) {
|
|
305
277
|
return true;
|
|
306
278
|
}
|
|
307
|
-
const matchedRoute = matchRoute(staticPath,
|
|
279
|
+
const matchedRoute = matchRoute(staticPath, options.manifest);
|
|
308
280
|
return matchedRoute === route;
|
|
309
281
|
});
|
|
310
282
|
for (const staticPath of paths) {
|
|
@@ -358,73 +330,31 @@ function getUrlForPath(pathname, base, origin, format, trailingSlash, routeType)
|
|
|
358
330
|
return url;
|
|
359
331
|
}
|
|
360
332
|
async function generatePath(pathname, pipeline, gopts, route) {
|
|
361
|
-
const { mod
|
|
362
|
-
const
|
|
363
|
-
const logger = pipeline.getLogger();
|
|
333
|
+
const { mod } = gopts;
|
|
334
|
+
const { config, logger, options, serverLike } = pipeline;
|
|
364
335
|
logger.debug("build", `Generating: ${pathname}`);
|
|
365
|
-
const links = /* @__PURE__ */ new Set();
|
|
366
|
-
const scripts = createModuleScriptsSet(
|
|
367
|
-
hoistedScripts ? [hoistedScripts] : [],
|
|
368
|
-
manifest.base,
|
|
369
|
-
manifest.assetsPrefix
|
|
370
|
-
);
|
|
371
|
-
const styles = createStylesheetElementSet(_styles, manifest.base, manifest.assetsPrefix);
|
|
372
|
-
if (pipeline.getSettings().scripts.some((script) => script.stage === "page")) {
|
|
373
|
-
const hashedFilePath = pipeline.getInternals().entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
|
|
374
|
-
if (typeof hashedFilePath !== "string") {
|
|
375
|
-
throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`);
|
|
376
|
-
}
|
|
377
|
-
const src = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
|
|
378
|
-
scripts.add({
|
|
379
|
-
props: { type: "module", src },
|
|
380
|
-
children: ""
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
for (const script of pipeline.getSettings().scripts) {
|
|
384
|
-
if (script.stage === "head-inline") {
|
|
385
|
-
scripts.add({
|
|
386
|
-
props: {},
|
|
387
|
-
children: script.content
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
336
|
if (route.type === "page") {
|
|
392
|
-
addPageName(pathname,
|
|
337
|
+
addPageName(pathname, options);
|
|
393
338
|
}
|
|
394
|
-
const ssr = isServerLikeOutput(pipeline.getConfig());
|
|
395
339
|
const url = getUrlForPath(
|
|
396
340
|
pathname,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
341
|
+
config.base,
|
|
342
|
+
options.origin,
|
|
343
|
+
config.build.format,
|
|
344
|
+
config.trailingSlash,
|
|
401
345
|
route.type
|
|
402
346
|
);
|
|
403
347
|
const request = createRequest({
|
|
404
348
|
url,
|
|
405
349
|
headers: new Headers(),
|
|
406
|
-
logger
|
|
407
|
-
ssr
|
|
408
|
-
});
|
|
409
|
-
const i18n = pipeline.getConfig().i18n;
|
|
410
|
-
const renderContext = await createRenderContext({
|
|
411
|
-
pathname,
|
|
412
|
-
request,
|
|
413
|
-
componentMetadata: manifest.componentMetadata,
|
|
414
|
-
scripts,
|
|
415
|
-
styles,
|
|
416
|
-
links,
|
|
417
|
-
route,
|
|
418
|
-
env: pipeline.getEnvironment(),
|
|
419
|
-
mod,
|
|
420
|
-
locales: i18n?.locales,
|
|
421
|
-
routing: i18n?.routing,
|
|
422
|
-
defaultLocale: i18n?.defaultLocale
|
|
350
|
+
logger,
|
|
351
|
+
ssr: serverLike
|
|
423
352
|
});
|
|
353
|
+
const renderContext = RenderContext.create({ pipeline, pathname, request, routeData: route });
|
|
424
354
|
let body;
|
|
425
355
|
let response;
|
|
426
356
|
try {
|
|
427
|
-
response = await
|
|
357
|
+
response = await renderContext.render(mod);
|
|
428
358
|
} catch (err) {
|
|
429
359
|
if (!AstroError.is(err) && !err.id && typeof err === "object") {
|
|
430
360
|
err.id = route.component;
|
|
@@ -432,13 +362,13 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
432
362
|
throw err;
|
|
433
363
|
}
|
|
434
364
|
if (response.status >= 300 && response.status < 400) {
|
|
435
|
-
if (!
|
|
365
|
+
if (!config.build.redirects) {
|
|
436
366
|
return;
|
|
437
367
|
}
|
|
438
368
|
const locationSite = getRedirectLocationOrThrow(response.headers);
|
|
439
|
-
const siteURL =
|
|
369
|
+
const siteURL = config.site;
|
|
440
370
|
const location = siteURL ? new URL(locationSite, siteURL) : locationSite;
|
|
441
|
-
const fromPath = new URL(
|
|
371
|
+
const fromPath = new URL(request.url).pathname;
|
|
442
372
|
const delay = response.status === 302 ? 2 : 0;
|
|
443
373
|
body = `<!doctype html>
|
|
444
374
|
<title>Redirecting to: ${location}</title>
|
|
@@ -448,7 +378,7 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
448
378
|
<body>
|
|
449
379
|
<a href="${location}">Redirecting from <code>${fromPath}</code> to <code>${location}</code></a>
|
|
450
380
|
</body>`;
|
|
451
|
-
if (
|
|
381
|
+
if (config.compressHTML === true) {
|
|
452
382
|
body = body.replaceAll("\n", "");
|
|
453
383
|
}
|
|
454
384
|
if (route.type !== "redirect") {
|
|
@@ -459,8 +389,8 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
459
389
|
return;
|
|
460
390
|
body = Buffer.from(await response.arrayBuffer());
|
|
461
391
|
}
|
|
462
|
-
const outFolder = getOutFolder(
|
|
463
|
-
const outFile = getOutFile(
|
|
392
|
+
const outFolder = getOutFolder(config, pathname, route);
|
|
393
|
+
const outFile = getOutFile(config, outFolder, pathname, route);
|
|
464
394
|
route.distURL = outFile;
|
|
465
395
|
await fs.promises.mkdir(outFolder, { recursive: true });
|
|
466
396
|
await fs.promises.writeFile(outFile, body);
|
package/dist/core/build/index.js
CHANGED
|
@@ -18,7 +18,6 @@ import { createSettings } from "../config/settings.js";
|
|
|
18
18
|
import { createVite } from "../create-vite.js";
|
|
19
19
|
import { levels, timerMessage } from "../logger/core.js";
|
|
20
20
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
21
|
-
import { RouteCache } from "../render/route-cache.js";
|
|
22
21
|
import { createRouteManifest } from "../routing/index.js";
|
|
23
22
|
import { collectPagesData } from "./page-data.js";
|
|
24
23
|
import { staticBuild, viteBuild } from "./static-build.js";
|
|
@@ -51,7 +50,6 @@ class AstroBuilder {
|
|
|
51
50
|
logger;
|
|
52
51
|
mode = "production";
|
|
53
52
|
origin;
|
|
54
|
-
routeCache;
|
|
55
53
|
manifest;
|
|
56
54
|
timer;
|
|
57
55
|
teardownCompiler;
|
|
@@ -62,7 +60,6 @@ class AstroBuilder {
|
|
|
62
60
|
this.settings = settings;
|
|
63
61
|
this.logger = options.logger;
|
|
64
62
|
this.teardownCompiler = options.teardownCompiler ?? true;
|
|
65
|
-
this.routeCache = new RouteCache(this.logger);
|
|
66
63
|
this.origin = settings.config.site ? new URL(settings.config.site).origin : `http://localhost:${settings.config.server.port}`;
|
|
67
64
|
this.manifest = { routes: [] };
|
|
68
65
|
this.timer = {};
|
|
@@ -130,7 +127,6 @@ class AstroBuilder {
|
|
|
130
127
|
mode: this.mode,
|
|
131
128
|
origin: this.origin,
|
|
132
129
|
pageNames,
|
|
133
|
-
routeCache: this.routeCache,
|
|
134
130
|
teardownCompiler: this.teardownCompiler,
|
|
135
131
|
viteConfig
|
|
136
132
|
};
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouteData, SSRResult } from '../../@types/astro.js';
|
|
2
2
|
import type { SSRManifest } from '../app/types.js';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import type { BuildInternals } from './internal.js';
|
|
3
|
+
import { Pipeline } from '../render/index.js';
|
|
4
|
+
import { type BuildInternals } from './internal.js';
|
|
6
5
|
import type { PageBuildData, StaticBuildOptions } from './types.js';
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
7
|
+
* The build pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files.
|
|
9
8
|
*/
|
|
10
9
|
export declare class BuildPipeline extends Pipeline {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getLogger(): Logger;
|
|
10
|
+
readonly internals: BuildInternals;
|
|
11
|
+
readonly manifest: SSRManifest;
|
|
12
|
+
readonly options: StaticBuildOptions;
|
|
13
|
+
readonly config: import("../../@types/astro.js").AstroConfig;
|
|
14
|
+
readonly settings: import("../../@types/astro.js").AstroSettings;
|
|
15
|
+
private constructor();
|
|
16
|
+
static create({ internals, manifest, options, }: Pick<BuildPipeline, 'internals' | 'manifest' | 'options'>): BuildPipeline;
|
|
19
17
|
/**
|
|
20
18
|
* The SSR build emits two important files:
|
|
21
19
|
* - dist/server/manifest.mjs
|
|
@@ -30,6 +28,8 @@ export declare class BuildPipeline extends Pipeline {
|
|
|
30
28
|
* @param staticBuildOptions
|
|
31
29
|
*/
|
|
32
30
|
static retrieveManifest(staticBuildOptions: StaticBuildOptions, internals: BuildInternals): Promise<SSRManifest>;
|
|
31
|
+
headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
|
|
32
|
+
componentMetadata(): void;
|
|
33
33
|
/**
|
|
34
34
|
* It collects the routes to generate during the build.
|
|
35
35
|
*
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { getOutputDirectory, isServerLikeOutput } from "../../prerender/utils.js";
|
|
2
|
+
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
3
|
+
import { routeIsFallback, routeIsRedirect } from "../redirects/helpers.js";
|
|
4
|
+
import { Pipeline } from "../render/index.js";
|
|
5
|
+
import {
|
|
6
|
+
createAssetLink,
|
|
7
|
+
createModuleScriptsSet,
|
|
8
|
+
createStylesheetElementSet
|
|
9
|
+
} from "../render/ssr-element.js";
|
|
10
|
+
import {
|
|
11
|
+
getPageDataByComponent,
|
|
12
|
+
cssOrder,
|
|
13
|
+
mergeInlineCss
|
|
14
|
+
} from "./internal.js";
|
|
15
|
+
import {
|
|
16
|
+
ASTRO_PAGE_RESOLVED_MODULE_ID,
|
|
17
|
+
getVirtualModulePageNameFromPath
|
|
18
|
+
} from "./plugins/plugin-pages.js";
|
|
19
|
+
import { RESOLVED_SPLIT_MODULE_ID } from "./plugins/plugin-ssr.js";
|
|
20
|
+
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
|
|
21
|
+
import { i18nHasFallback } from "./util.js";
|
|
22
|
+
class BuildPipeline extends Pipeline {
|
|
23
|
+
constructor(internals, manifest, options, config = options.settings.config, settings = options.settings) {
|
|
24
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
25
|
+
async function resolve(specifier) {
|
|
26
|
+
if (resolveCache.has(specifier)) {
|
|
27
|
+
return resolveCache.get(specifier);
|
|
28
|
+
}
|
|
29
|
+
const hashedFilePath = manifest.entryModules[specifier];
|
|
30
|
+
if (typeof hashedFilePath !== "string" || hashedFilePath === "") {
|
|
31
|
+
if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
|
|
32
|
+
resolveCache.set(specifier, "");
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
36
|
+
}
|
|
37
|
+
const assetLink = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
|
|
38
|
+
resolveCache.set(specifier, assetLink);
|
|
39
|
+
return assetLink;
|
|
40
|
+
}
|
|
41
|
+
const serverLike = isServerLikeOutput(config);
|
|
42
|
+
const streaming = true;
|
|
43
|
+
super(
|
|
44
|
+
options.logger,
|
|
45
|
+
manifest,
|
|
46
|
+
options.mode,
|
|
47
|
+
manifest.renderers,
|
|
48
|
+
resolve,
|
|
49
|
+
serverLike,
|
|
50
|
+
streaming
|
|
51
|
+
);
|
|
52
|
+
this.internals = internals;
|
|
53
|
+
this.manifest = manifest;
|
|
54
|
+
this.options = options;
|
|
55
|
+
this.config = config;
|
|
56
|
+
this.settings = settings;
|
|
57
|
+
}
|
|
58
|
+
static create({
|
|
59
|
+
internals,
|
|
60
|
+
manifest,
|
|
61
|
+
options
|
|
62
|
+
}) {
|
|
63
|
+
return new BuildPipeline(internals, manifest, options);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The SSR build emits two important files:
|
|
67
|
+
* - dist/server/manifest.mjs
|
|
68
|
+
* - dist/renderers.mjs
|
|
69
|
+
*
|
|
70
|
+
* These two files, put together, will be used to generate the pages.
|
|
71
|
+
*
|
|
72
|
+
* ## Errors
|
|
73
|
+
*
|
|
74
|
+
* It will throw errors if the previous files can't be found in the file system.
|
|
75
|
+
*
|
|
76
|
+
* @param staticBuildOptions
|
|
77
|
+
*/
|
|
78
|
+
static async retrieveManifest(staticBuildOptions, internals) {
|
|
79
|
+
const config = staticBuildOptions.settings.config;
|
|
80
|
+
const baseDirectory = getOutputDirectory(config);
|
|
81
|
+
const manifestEntryUrl = new URL(
|
|
82
|
+
`${internals.manifestFileName}?time=${Date.now()}`,
|
|
83
|
+
baseDirectory
|
|
84
|
+
);
|
|
85
|
+
const { manifest } = await import(manifestEntryUrl.toString());
|
|
86
|
+
if (!manifest) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"Astro couldn't find the emitted manifest. This is an internal error, please file an issue."
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const renderersEntryUrl = new URL(`renderers.mjs?time=${Date.now()}`, baseDirectory);
|
|
92
|
+
const renderers = await import(renderersEntryUrl.toString());
|
|
93
|
+
const middleware = await import(new URL("middleware.mjs", baseDirectory).toString()).then((mod) => mod.onRequest).catch(() => manifest.middleware);
|
|
94
|
+
if (!renderers) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"Astro couldn't find the emitted renderers. This is an internal error, please file an issue."
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...manifest,
|
|
101
|
+
renderers: renderers.renderers,
|
|
102
|
+
middleware
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
headElements(routeData) {
|
|
106
|
+
const {
|
|
107
|
+
internals,
|
|
108
|
+
manifest: { assetsPrefix, base },
|
|
109
|
+
settings
|
|
110
|
+
} = this;
|
|
111
|
+
const links = /* @__PURE__ */ new Set();
|
|
112
|
+
const pageBuildData = getPageDataByComponent(internals, routeData.component);
|
|
113
|
+
const scripts = createModuleScriptsSet(
|
|
114
|
+
pageBuildData?.hoistedScript ? [pageBuildData.hoistedScript] : [],
|
|
115
|
+
base,
|
|
116
|
+
assetsPrefix
|
|
117
|
+
);
|
|
118
|
+
const sortedCssAssets = pageBuildData?.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
|
|
119
|
+
const styles = createStylesheetElementSet(sortedCssAssets ?? [], base, assetsPrefix);
|
|
120
|
+
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
121
|
+
const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
|
|
122
|
+
if (typeof hashedFilePath !== "string") {
|
|
123
|
+
throw new Error(`Cannot find the built path for ${PAGE_SCRIPT_ID}`);
|
|
124
|
+
}
|
|
125
|
+
const src = createAssetLink(hashedFilePath, base, assetsPrefix);
|
|
126
|
+
scripts.add({
|
|
127
|
+
props: { type: "module", src },
|
|
128
|
+
children: ""
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
for (const script of settings.scripts) {
|
|
132
|
+
if (script.stage === "head-inline") {
|
|
133
|
+
scripts.add({
|
|
134
|
+
props: {},
|
|
135
|
+
children: script.content
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { scripts, styles, links };
|
|
140
|
+
}
|
|
141
|
+
componentMetadata() {
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* It collects the routes to generate during the build.
|
|
145
|
+
*
|
|
146
|
+
* It returns a map of page information and their relative entry point as a string.
|
|
147
|
+
*/
|
|
148
|
+
retrieveRoutesToGenerate() {
|
|
149
|
+
const pages = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const [entrypoint, filePath] of this.internals.entrySpecifierToBundleMap) {
|
|
151
|
+
if (entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || entrypoint.includes(RESOLVED_SPLIT_MODULE_ID)) {
|
|
152
|
+
const [, pageName] = entrypoint.split(":");
|
|
153
|
+
const pageData = this.internals.pagesByComponent.get(
|
|
154
|
+
`${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".")}`
|
|
155
|
+
);
|
|
156
|
+
if (!pageData) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
"Build failed. Astro couldn't find the emitted page from " + pageName + " pattern"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
pages.set(pageData, filePath);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const [path, pageData] of this.internals.pagesByComponent.entries()) {
|
|
165
|
+
if (routeIsRedirect(pageData.route)) {
|
|
166
|
+
pages.set(pageData, path);
|
|
167
|
+
} else if (routeIsFallback(pageData.route) && (i18nHasFallback(this.config) || routeIsFallback(pageData.route) && pageData.route.route === "/")) {
|
|
168
|
+
const moduleSpecifier = getVirtualModulePageNameFromPath(path);
|
|
169
|
+
const filePath = this.internals.entrySpecifierToBundleMap.get(moduleSpecifier);
|
|
170
|
+
if (filePath) {
|
|
171
|
+
pages.set(pageData, filePath);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return pages;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
BuildPipeline
|
|
180
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {} from "vite";
|
|
2
1
|
import { isBuildableCSSRequest } from "../../../vite-plugin-astro-server/util.js";
|
|
3
2
|
import { PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
|
|
4
3
|
import * as assetName from "../css-asset-name.js";
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
getPageDatasByHoistedScriptId,
|
|
11
10
|
isHoistedScript
|
|
12
11
|
} from "../internal.js";
|
|
13
|
-
import { extendManualChunks } from "./util.js";
|
|
12
|
+
import { extendManualChunks, shouldInlineAsset } from "./util.js";
|
|
14
13
|
function pluginCSS(options, internals) {
|
|
15
14
|
return {
|
|
16
15
|
targets: ["client", "server"],
|
|
@@ -146,17 +145,19 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
};
|
|
148
|
+
let assetsInlineLimit;
|
|
149
149
|
const inlineStylesheetsPlugin = {
|
|
150
150
|
name: "astro:rollup-plugin-inline-stylesheets",
|
|
151
151
|
enforce: "post",
|
|
152
|
+
configResolved(config) {
|
|
153
|
+
assetsInlineLimit = config.build.assetsInlineLimit;
|
|
154
|
+
},
|
|
152
155
|
async generateBundle(_outputOptions, bundle) {
|
|
153
156
|
const inlineConfig = settings.config.build.inlineStylesheets;
|
|
154
|
-
const { assetsInlineLimit = 4096 } = settings.config.vite?.build ?? {};
|
|
155
157
|
Object.entries(bundle).forEach(([id, stylesheet]) => {
|
|
156
158
|
if (stylesheet.type !== "asset" || stylesheet.name?.endsWith(".css") !== true || typeof stylesheet.source !== "string")
|
|
157
159
|
return;
|
|
158
|
-
const
|
|
159
|
-
const toBeInlined = inlineConfig === "always" ? true : inlineConfig === "never" ? false : assetSize <= assetsInlineLimit;
|
|
160
|
+
const toBeInlined = inlineConfig === "always" ? true : inlineConfig === "never" ? false : shouldInlineAsset(stylesheet.source, stylesheet.fileName, assetsInlineLimit);
|
|
160
161
|
const sheet = toBeInlined ? { type: "inline", content: stylesheet.source } : { type: "external", src: stylesheet.fileName };
|
|
161
162
|
const pages = Array.from(eachPageData(internals));
|
|
162
163
|
let sheetAddedToPage = false;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { viteID } from "../../util.js";
|
|
2
2
|
import { getPageDataByViteID } from "../internal.js";
|
|
3
|
+
import { shouldInlineAsset } from "./util.js";
|
|
3
4
|
function virtualHoistedEntry(id) {
|
|
4
5
|
return id.startsWith("/astro/hoisted.js?q=");
|
|
5
6
|
}
|
|
6
7
|
function vitePluginHoistedScripts(settings, internals) {
|
|
8
|
+
let assetsInlineLimit;
|
|
7
9
|
return {
|
|
8
10
|
name: "@astro/rollup-plugin-astro-hoisted-scripts",
|
|
11
|
+
configResolved(config) {
|
|
12
|
+
assetsInlineLimit = config.build.assetsInlineLimit;
|
|
13
|
+
},
|
|
9
14
|
resolveId(id) {
|
|
10
15
|
if (virtualHoistedEntry(id)) {
|
|
11
16
|
return id;
|
|
@@ -28,10 +33,6 @@ function vitePluginHoistedScripts(settings, internals) {
|
|
|
28
33
|
return void 0;
|
|
29
34
|
},
|
|
30
35
|
async generateBundle(_options, bundle) {
|
|
31
|
-
let assetInlineLimit = 4096;
|
|
32
|
-
if (settings.config.vite?.build && settings.config.vite.build.assetsInlineLimit !== void 0) {
|
|
33
|
-
assetInlineLimit = settings.config.vite?.build.assetsInlineLimit;
|
|
34
|
-
}
|
|
35
36
|
const considerInlining = /* @__PURE__ */ new Map();
|
|
36
37
|
const importedByOtherScripts = /* @__PURE__ */ new Set();
|
|
37
38
|
Object.entries(bundle).forEach(([id, output]) => {
|
|
@@ -41,7 +42,7 @@ function vitePluginHoistedScripts(settings, internals) {
|
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
for (const [id, output] of considerInlining.entries()) {
|
|
44
|
-
const canBeInlined = importedByOtherScripts.has(output.fileName) === false && output.imports.length === 0 && output.dynamicImports.length === 0 &&
|
|
45
|
+
const canBeInlined = importedByOtherScripts.has(output.fileName) === false && output.imports.length === 0 && output.dynamicImports.length === 0 && shouldInlineAsset(output.code, output.fileName, assetsInlineLimit);
|
|
45
46
|
let removeFromBundle = false;
|
|
46
47
|
const facadeId = output.facadeModuleId;
|
|
47
48
|
const pages = internals.hoistedScriptIdToPagesMap.get(facadeId);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Rollup, Plugin as VitePlugin } from 'vite';
|
|
1
|
+
import type { BuildOptions, Rollup, Plugin as VitePlugin } from 'vite';
|
|
2
2
|
type OutputOptionsHook = Extract<VitePlugin['outputOptions'], Function>;
|
|
3
3
|
type OutputOptions = Parameters<OutputOptionsHook>[0];
|
|
4
4
|
type ExtendManualChunksHooks = {
|
|
@@ -21,4 +21,5 @@ export declare function getVirtualModulePageNameFromPath(virtualModulePrefix: st
|
|
|
21
21
|
* @param id
|
|
22
22
|
*/
|
|
23
23
|
export declare function getPathFromVirtualModulePageName(virtualModulePrefix: string, id: string): string;
|
|
24
|
+
export declare function shouldInlineAsset(assetContent: string, assetPath: string, assetsInlineLimit: NonNullable<BuildOptions['assetsInlineLimit']>): boolean;
|
|
24
25
|
export {};
|
|
@@ -37,9 +37,20 @@ function getPathFromVirtualModulePageName(virtualModulePrefix, id) {
|
|
|
37
37
|
const pageName = id.slice(virtualModulePrefix.length);
|
|
38
38
|
return pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".");
|
|
39
39
|
}
|
|
40
|
+
function shouldInlineAsset(assetContent, assetPath, assetsInlineLimit) {
|
|
41
|
+
if (typeof assetsInlineLimit === "number") {
|
|
42
|
+
return Buffer.byteLength(assetContent) < assetsInlineLimit;
|
|
43
|
+
}
|
|
44
|
+
const result = assetsInlineLimit(assetPath, Buffer.from(assetContent));
|
|
45
|
+
if (result != null) {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
return Buffer.byteLength(assetContent) < 4096;
|
|
49
|
+
}
|
|
40
50
|
export {
|
|
41
51
|
ASTRO_PAGE_EXTENSION_POST_PATTERN,
|
|
42
52
|
extendManualChunks,
|
|
43
53
|
getPathFromVirtualModulePageName,
|
|
44
|
-
getVirtualModulePageNameFromPath
|
|
54
|
+
getVirtualModulePageNameFromPath,
|
|
55
|
+
shouldInlineAsset
|
|
45
56
|
};
|