-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: improve rolldown compatibility #13519
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
273d30f
feat: improve rolldown compatibility
florian-lefebvre 213c707
Merge branch 'main' into feat/rolldown-led-improvements
florian-lefebvre e5e60ab
chore: remove moduleType
florian-lefebvre 595976b
feat: use object shape
florian-lefebvre 5bf450a
chore: changeset
florian-lefebvre a9faa4e
Merge branch 'main' into feat/rolldown-led-improvements
florian-lefebvre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,32 +117,35 @@ export default function assets({ settings }: { settings: AstroSettings }): vite. | |
| }, | ||
| load(id) { | ||
| if (id === resolvedVirtualModuleId) { | ||
| return /* ts */ ` | ||
| export { getConfiguredImageService, isLocalService } from "astro/assets"; | ||
| import { getImage as getImageInternal } from "astro/assets"; | ||
| export { default as Image } from "astro/components/${imageComponentPrefix}Image.astro"; | ||
| export { default as Picture } from "astro/components/${imageComponentPrefix}Picture.astro"; | ||
| export { inferRemoteSize } from "astro/assets/utils/inferRemoteSize.js"; | ||
|
|
||
| export const imageConfig = ${JSON.stringify({ ...settings.config.image, experimentalResponsiveImages: settings.config.experimental.responsiveImages })}; | ||
| // 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( | ||
| settings.buildOutput === 'server' | ||
| ? settings.config.build.client | ||
| : settings.config.outDir, | ||
| ), | ||
| )}); | ||
| export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify( | ||
| settings.config.build.assets, | ||
| )}, outDir); | ||
| export const getImage = async (options) => await getImageInternal(options, imageConfig); | ||
| `; | ||
| return { | ||
| code: /* ts */ ` | ||
florian-lefebvre marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export { getConfiguredImageService, isLocalService } from "astro/assets"; | ||
| import { getImage as getImageInternal } from "astro/assets"; | ||
| export { default as Image } from "astro/components/${imageComponentPrefix}Image.astro"; | ||
| export { default as Picture } from "astro/components/${imageComponentPrefix}Picture.astro"; | ||
| export { inferRemoteSize } from "astro/assets/utils/inferRemoteSize.js"; | ||
|
|
||
| export const imageConfig = ${JSON.stringify({ ...settings.config.image, experimentalResponsiveImages: settings.config.experimental.responsiveImages })}; | ||
| // 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( | ||
| settings.buildOutput === 'server' | ||
| ? settings.config.build.client | ||
| : settings.config.outDir, | ||
| ), | ||
| )}); | ||
| export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify( | ||
| settings.config.build.assets, | ||
| )}, outDir); | ||
| export const getImage = async (options) => await getImageInternal(options, imageConfig); | ||
| `, | ||
| moduleType: 'js', | ||
| }; | ||
| } | ||
| }, | ||
| buildStart() { | ||
|
|
@@ -151,7 +154,7 @@ export default function assets({ settings }: { settings: AstroSettings }): vite. | |
| }, | ||
| // In build, rewrite paths to ESM imported images in code to their final location | ||
| async renderChunk(code) { | ||
| const assetUrlRE = /__ASTRO_ASSET_IMAGE__([\w$]{8})__(?:_(.*?)__)?/g; | ||
| const assetUrlRE = /__ASTRO_ASSET_IMAGE__([\w$]+)__(?:_(.*?)__)?/g; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In rolldown hashes are not exactly 8 long |
||
|
|
||
| let match; | ||
| let s; | ||
|
|
@@ -205,7 +208,7 @@ export default function assets({ settings }: { settings: AstroSettings }): vite. | |
| return; | ||
| } | ||
|
|
||
| const emitFile = shouldEmitFile ? this.emitFile : undefined; | ||
| const emitFile = shouldEmitFile ? this.emitFile.bind(this) : undefined; | ||
| const imageMetadata = await emitESMImage( | ||
| id, | ||
| this.meta.watchMode, | ||
|
|
@@ -223,22 +226,31 @@ export default function assets({ settings }: { settings: AstroSettings }): vite. | |
| if (settings.config.experimental.svg && /\.svg$/.test(id)) { | ||
| const { contents, ...metadata } = imageMetadata; | ||
| // We know that the contents are present, as we only emit this property for SVG files | ||
| return makeSvgComponent(metadata, contents!, { | ||
| mode: settings.config.experimental.svg.mode, | ||
| }); | ||
| return { | ||
florian-lefebvre marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| code: makeSvgComponent(metadata, contents!, { | ||
| mode: settings.config.experimental.svg.mode, | ||
| }), | ||
| moduleType: 'js', | ||
| }; | ||
| } | ||
|
|
||
| // We can only reliably determine if an image is used on the server, as we need to track its usage throughout the entire build. | ||
| // Since you cannot use image optimization on the client anyway, it's safe to assume that if the user imported | ||
| // an image on the client, it should be present in the final build. | ||
| if (options?.ssr) { | ||
| return `export default ${getProxyCode( | ||
| imageMetadata, | ||
| settings.buildOutput === 'server', | ||
| )}`; | ||
| return { | ||
florian-lefebvre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| code: `export default ${getProxyCode( | ||
| imageMetadata, | ||
| settings.buildOutput === 'server', | ||
| )}`, | ||
| moduleType: 'js', | ||
| }; | ||
| } else { | ||
| globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath); | ||
| return `export default ${JSON.stringify(imageMetadata)}`; | ||
| return { | ||
florian-lefebvre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| code: `export default ${JSON.stringify(imageMetadata)}`, | ||
| moduleType: 'js', | ||
| }; | ||
| } | ||
| } | ||
| }, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,9 @@ function getNonPrerenderOnlyChunks(bundle: Rollup.OutputBundle, internals: Build | |
|
|
||
| nonPrerenderOnlyEntryChunks.add(chunk); | ||
| } | ||
| if (chunk.type === 'chunk' && chunk.isDynamicEntry) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a bug in Astro according to the patch file |
||
| nonPrerenderOnlyEntryChunks.add(chunk); | ||
| } | ||
| } | ||
|
|
||
| // From the `nonPrerenderedEntryChunks`, we crawl all the imports/dynamicImports to find all | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.