Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure outDir doesn't lead to bundlers bloating Lambda size #10550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-impalas-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes bug where server builds would include unneeded assets in SSR Function, potentially leading to upload errors on Vercel, Netlify because of size limits
10 changes: 8 additions & 2 deletions packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ export default function assets({
export { default as Picture } from "astro/components/Picture.astro";

export const imageConfig = ${JSON.stringify(settings.config.image)};
export const outDir = new URL(${JSON.stringify(
// This is used by the @astrojs/node integration to locate images.
// It's unused on other platforms, but on some platforms like Netlify (and presumably also Vercel)
// new URL("dist/...") is interpreted by the bundler as a signal to include that directory
// in the Lambda bundle, which would bloat the bundle with images.
// To prevent this, we mark the URL construction as pure,
// so that it's tree-shaken away for all platforms that don't need it.
export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
new URL(
isServerLikeOutput(settings.config)
? settings.config.build.client
: settings.config.outDir
)
)});
export const assetsDir = new URL(${JSON.stringify(settings.config.build.assets)}, outDir);
export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify(settings.config.build.assets)}, outDir);
export const getImage = async (options) => await getImageInternal(options, imageConfig);
`;
}
Expand Down
12 changes: 12 additions & 0 deletions packages/integrations/vercel/test/serverless-prerender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ describe('Serverless prerender', () => {
assert.ok(await fixture.readFile('../.vercel/output/static/index.html'));
});

it('outDir is tree-shaken if not needed', async () => {
const [file] = await fixture.glob(
'../.vercel/output/functions/_render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/.vercel/output/_functions/chunks/pages/generic_*.mjs'
);
const contents = await fixture.readFile(file);
console.log(contents)
assert.ok(
!contents.includes('const outDir ='),
"outDir is tree-shaken if it's not imported"
);
});

// TODO: The path here seems to be inconsistent?
it.skip('includeFiles work', async () => {
assert.ok(
Expand Down
Loading