URL bundled assets and Single File Executable (SFE) #1204
Replies: 3 comments 1 reply
-
Just a heads up on this bug that came up during alpha testing the original feature - #1210 |
Beta Was this translation helpful? Give feedback.
-
So ran into an issue in #1465 where-in bundling an API route (using the AWS SDK) emitted a bunch of extra bundle chunks In a couple attempts to solve this problem, I found some seemingly promising results to truly achieve SFEs, but none came "quite" close, with a lot of the ideas coming out from this Rollup issue
|
Beta Was this translation helpful? Give feedback.
-
Also, I think there's a slight dis-connect in that for API routes we specifically have to check for additional chunk assets for (const [key, value] of apiRoutes.entries()) {
const outputType = "api";
const { id, outputHref } = apiRoutes.get(key);
const outputRoot = new URL(`.${basePath}/api/${id}/`, adapterOutputUrl);
const { assets = [] } = value;
// ...
for (const asset of assets) {
const name = path.basename(asset);
await fs.cp(new URL(asset), new URL(`./${name}`, outputRoot), { recursive: true });
}
} But with SSR pages seems like we can just pattern match for (const page of ssrPages) {
const outputType = "page";
const { id, outputHref } = page;
const outputRoot = new URL(`./routes/${basePath}/${id}/`, adapterOutputUrl);
const chunks = (await fs.readdir(outputDir)).filter(
(file) => file.startsWith(`${id}.route.chunk`) && file.endsWith(".js"),
);
// ...
// and any (URL) chunks for the page
for (const chunk of chunks) {
await fs.cp(new URL(`./${chunk}`, outputDir), new URL(`./${chunk}`, outputRoot), {
recursive: true,
});
}
} So maybe that could be cleaned up a bit too? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
Coming out of the PR for #1186 , a couples techniques / refactorings were applied around the usage of
URL
for consuming assets with project files and for combining user page routes and the underlyingexecuteRouteModule
implementation.For example, a user could write this in an API route
And when bundling SSR pages for production, Greenwood does something like this
Problem Statement
Not so much a "problem" per se, since this technique works really and is standards compliant, but will never allow us to totally self contain a bunch of files down to one. For example, when bundling an SSR page, you will always have a single output file (good) but also need a "chunk" file that is the by product of the above mentioned bundling approach.
Or for an API route, an adjacent chunk
It does mean for adapters they do need to do something like, and manually copy over any assets of say an API route
h3. Thoughts
So not so much a good or bad thing, or if anyone would really notice and or want it improved from a user perspective, but there is something really nice a about a final single file artifact that can be deployed all one. Maybe there is a way to convert a URL into something more like an
import
statement that could then be inlined?Anyway, more thinking out loud, hence the discussion.
Beta Was this translation helpful? Give feedback.
All reactions