Skip to content

Commit 91e7bfb

Browse files
LekoArtsgatsbybot
andauthored
fix(gatsby-transformer-sharp): Add checkSupportedExtensions… (#22565)
* Add 'checkSupportedExtensions' option * modify "parsing algorithm" note Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
1 parent 2d6f701 commit 91e7bfb

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

packages/gatsby-transformer-sharp/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ It recognizes files with the following extensions as images.
3838

3939
Each image file is parsed into a node of type `ImageSharp`.
4040

41+
## Configuration options
42+
43+
`checkSupportedExtensions` [boolean][optional]
44+
45+
Sharp only supports certain image formats (see the Parsing algorithm section above) and hence throws a warning when you e.g. use a .gif in an `ImageSharp` query. You'll need to use `publicURL` instead. With this option you can disable the warning behavior.
46+
47+
```javascript
48+
// In your gatsby-config.js
49+
module.exports = {
50+
plugins: [
51+
`gatsby-plugin-sharp`,
52+
{
53+
resolve: `gatsby-transformer-sharp`,
54+
options: {
55+
// The option defaults to true
56+
checkSupportedExtensions: false,
57+
},
58+
},
59+
],
60+
}
61+
```
62+
4163
## Troubleshooting
4264

4365
### Incompatible library version: sharp.node requires version X or later, but Z provides version Y

packages/gatsby-transformer-sharp/src/create-resolvers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
const { supportedExtensions } = require(`./supported-extensions`)
22

3-
module.exports = ({ createResolvers, reporter }) => {
3+
module.exports = ({ createResolvers, reporter }, pluginOptions = {}) => {
4+
const { checkSupportedExtensions = true } = pluginOptions
5+
46
const resolvers = {
57
File: {
68
childImageSharp: {
79
resolve: (parent, args, context, info) => {
8-
if (!supportedExtensions[parent.extension]) {
10+
// TODO: In future when components from GraphQL are possible make sure that we can support both supported & unsupported image formats
11+
if (
12+
!supportedExtensions[parent.extension] &&
13+
checkSupportedExtensions
14+
) {
915
reporter.warn(
1016
`You can't use childImageSharp together with ${parent.name}.${parent.extension} — use publicURL instead. The childImageSharp portion of the query in this file will return null:\n${context.componentPath}`
1117
)

0 commit comments

Comments
 (0)