-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: add experimental responsive images config option #12378
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ export const ASTRO_CONFIG_DEFAULTS = { | |
experimental: { | ||
clientPrerender: false, | ||
contentIntellisense: false, | ||
responsiveImages: false, | ||
}, | ||
} satisfies AstroUserConfig & { server: { open: boolean } }; | ||
|
||
|
@@ -525,6 +526,22 @@ export const AstroConfigSchema = z.object({ | |
.boolean() | ||
.optional() | ||
.default(ASTRO_CONFIG_DEFAULTS.experimental.contentIntellisense), | ||
responsiveImages: z | ||
.union([ | ||
z.boolean(), | ||
z.object({ | ||
layout: z | ||
.union([ | ||
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. you can use 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. Oh yeah duh! |
||
z.literal('responsive'), | ||
z.literal('fixed'), | ||
z.literal('full-width'), | ||
z.literal('none'), | ||
]) | ||
.optional(), | ||
}), | ||
]) | ||
.optional() | ||
.default(ASTRO_CONFIG_DEFAULTS.experimental.responsiveImages), | ||
ascorbic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
.strict( | ||
`Invalid or outdated experimental feature.\nCheck for incorrect spelling or outdated Astro version.\nSee https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for a list of all current experiments.`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1699,9 +1699,46 @@ export interface ViteUserConfig extends OriginalViteUserConfig { | |
* To use this feature with the Astro VS Code extension, you must also enable the `astro.content-intellisense` option in your VS Code settings. For editors using the Astro language server directly, pass the `contentIntellisense: true` initialization parameter to enable this feature. | ||
*/ | ||
contentIntellisense?: boolean; | ||
|
||
/** | ||
* @docs | ||
* @name experimental.responsiveImages | ||
* @type {boolean} | ||
* @default `undefined` | ||
* @version 5.0.0 | ||
* @description | ||
* | ||
* Enables and configures automatic responsive image generation for images in your project. Set to `true` or an object with configuration options. | ||
* When enabled it will not transform any images unless you pass the `layout` option to the image component, or set the `layout` option in the `responsiveImages` configuration. | ||
ascorbic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* ```js | ||
* { | ||
* experimental: { | ||
* responsiveImages: { | ||
* layout: 'responsive', | ||
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 now changes in that you only set this to And, since we now have multiple properties (acknowledging there may still even be more to come!), when you do add the regular image config for this example, I would set at least a couple of them. (Not meaning to overly edit while stuff is still happening, just didn't want us to forget!) |
||
* }, | ||
* } | ||
* ``` | ||
* | ||
ascorbic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
responsiveImages?: | ||
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. should this be under 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. You mean as 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. Yeah, the normal top level 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. Is that something we do for experimental features? 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. We kinda have two philosophies, some people put it under experimental, some others don't. I personally think it makes the upgrading smoother when it's already where it will be, as you then don't need to move anything, but it's up to you really. It just felt a bit jarring to have both
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. That works perfectly for me! 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. @sarah11918 what are your thoughts on this? Should the config options for the feature go inside 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. I saw this discussion and was happy to let it play out. 😅 We have precedence for both! I don't have a strong opinion -- people are going to have to update their config either way in the cases you've described: either they move The other option is also a bit wonky: just use So, I won't fight any of these options. I can make them all work and there's no clear and obvious winner here. I won't make the final call unless someone specifically wants me to. 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 the absence of any strong opinions on either side, I'll leave it as-is 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. Changed my mind again! I've gone for the second option |
||
| boolean | ||
| { | ||
/** | ||
* @docs | ||
* @name responsiveImages.layout | ||
* @default `undefined` | ||
* @description | ||
* The default layout type for responsive images. Can be overridden by the `layout` prop on the image component. | ||
ascorbic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
layout?: ResponsiveImageLayout | undefined; | ||
}; | ||
}; | ||
} | ||
|
||
export type ResponsiveImageLayout = 'responsive' | 'fixed' | 'full-width' | 'none'; | ||
|
||
/** | ||
* Resolved Astro Config | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how
updateConfig()
will behave if the user sets it as a boolean, and an integration setslayout