Skip to content

Commit

Permalink
make gatsby-plugin-image optional
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Dec 11, 2020
1 parent 7352949 commit 93aa12a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-source-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"contentful": "^7.14.12",
"fs-extra": "^9.0.1",
"gatsby-core-utils": "^1.6.0-next.0",
"gatsby-plugin-image": "^0.2.0-next.0",
"gatsby-plugin-utils": "^0.5.0-next.0",
"gatsby-source-filesystem": "^2.7.0-next.2",
"is-online": "^8.5.1",
Expand All @@ -43,6 +42,7 @@
"license": "MIT",
"peerDependencies": {
"gatsby": "^2.12.1",
"gatsby-plugin-image": "^0.3.0-next.0",
"gatsby-plugin-sharp": "^2.6.14"
},
"repository": {
Expand Down
53 changes: 34 additions & 19 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const fs = require(`fs`)
const path = require(`path`)
const crypto = require(`crypto`)
const { generateImageData } = require(`gatsby-plugin-image`)
const { getGatsbyImageFieldConfig } = require(`gatsby-plugin-image/graphql`)

const Promise = require(`bluebird`)
const {
Expand Down Expand Up @@ -152,6 +150,7 @@ const fitMap = new Map([
])

const resolveGatsbyImageData = async (image, options) => {
const { generateImageData } = require(`gatsby-plugin-image`)
const { baseUrl, ...sourceMetadata } = getBasicImageProps(image, options)

return generateImageData({
Expand Down Expand Up @@ -649,30 +648,46 @@ exports.extendNodeType = ({ type, store, cache, getNodesByType }) => {

const fluidNode = fluidNodeType({ name: `ContentfulFluid`, getTracedSVG })
const sizesNode = fluidNodeType({ name: `ContentfulSizes`, getTracedSVG })
const gatsbyImageData = getGatsbyImageFieldConfig(resolveGatsbyImageData, {
jpegProgressive: {
type: GraphQLBoolean,
defaultValue: true,
},
resizingBehavior: {
type: ImageResizingBehavior,
},
cropFocus: {
type: ImageCropFocusType,
},
quality: {
type: GraphQLInt,
defaultValue: 50,
},
})
sizesNode.deprecationReason = `Sizes was deprecated in Gatsby v2. It's been renamed to "fluid" https://example.com/write-docs-and-fix-this-example-link`

// gatsby-pugin-image
const getGatsbyImageData = () => {
// @todo check if gatsby-plugin-image is enabled
const gatsbyImageEnabled = false
if (!gatsbyImageEnabled) {
return {
type: GraphQLString,
deprecated: true,
deprecationReason: `Enable gatsby-plugin-image to use this field.`,
resolve: () => null,
}
}
const { getGatsbyImageFieldConfig } = require(`gatsby-plugin-image/graphql`)

return getGatsbyImageFieldConfig(resolveGatsbyImageData, {
jpegProgressive: {
type: GraphQLBoolean,
defaultValue: true,
},
resizingBehavior: {
type: ImageResizingBehavior,
},
cropFocus: {
type: ImageCropFocusType,
},
quality: {
type: GraphQLInt,
defaultValue: 50,
},
})
}

return {
fixed: fixedNode,
resolutions: resolutionsNode,
fluid: fluidNode,
sizes: sizesNode,
gatsbyImageData,
gatsbyImageData: getGatsbyImageData(),
resize: {
type: new GraphQLObjectType({
name: `ContentfulResize`,
Expand Down

0 comments on commit 93aa12a

Please sign in to comment.