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

feat(gatsby-plugin-sharp): Add image plugin defaults #29147

Merged
merged 2 commits into from
Jan 22, 2021

Conversation

ascorbic
Copy link
Contributor

Adds support for users to specify default values for most gatsby-plugin-image options. These are set on gatsby-plugin-sharp, in the defaults key.

e.g.

module.exports = {
  siteMetadata: {
    title: `Gatsby Plugin Image`,
  },
  plugins: [
    {
      resolve: `gatsby-plugin-sharp`,
      options: {
        defaults: {
          breakpoints: [100, 200, 300, 400],
          formats: ["auto", "webp", "avif"],
          transformOptions: {
            fit: "contain",
          },
        },
      },
    },
    `gatsby-transformer-sharp`,
    { resolve: `gatsby-source-filesystem`, options: { path: "./src/images/" } },
    `gatsby-plugin-image`,
  ],
}

[ch23484]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 22, 2021
Copy link
Contributor

@laurieontech laurieontech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question I have with this is whether it's more intuitive to pass these defaults to gatsby-plugin-image and let them pass on to sharp. I know that's not the plugin in charge of processing, but I expect that's how users will think about it?

@@ -215,4 +215,26 @@ exports.pluginOptionsSchema = ({ Joi }) =>
stripMetadata: Joi.boolean().default(true),
defaultQuality: Joi.number().default(50),
failOnError: Joi.boolean().default(true),
defaults: Joi.object({
formats: Joi.array().items(
Joi.string().valid(`auto`, `png`, `jpg`, `webp`, `avif`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is jpeg valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

pngOptions: Joi.object(),
webpOptions: Joi.object(),
avifOptions: Joi.object(),
}).description(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transformOptions? Any of the sizing stuff like aspectRatio?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the sizing options make sense to have as global defaults. I guess transformOptions could though. I'll add them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, my one thought was aspectRatio could, since it's more look and feel that strict sizing. But no strong feelings on that one.

@ascorbic ascorbic added bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: media Related to gatsby-plugin-image, or general image/media processing topics and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 22, 2021
@ascorbic ascorbic merged commit 8b6bfa6 into master Jan 22, 2021
@ascorbic ascorbic deleted the feat/image-plugin-defaults branch January 22, 2021 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: media Related to gatsby-plugin-image, or general image/media processing topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants