Skip to content

Commit

Permalink
feat: provide fragments without gatsby-image (#8459)
Browse files Browse the repository at this point in the history
* [gatsby-transformer-sharp] Provide fragments without gatsby-image

* Missed a line
  • Loading branch information
stefanprobst authored and pieh committed Sep 27, 2018
1 parent cc6fbac commit 3389b89
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions packages/gatsby-transformer-sharp/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,15 @@ exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`)
exports.onPreExtractQueries = async ({ store, getNodes }) => {
const program = store.getState().program

// Check if there are any ImageSharp nodes and if gatsby-image is installed. If so
// add fragments for ImageSharp and gatsby-image. The fragment will cause an error
// if there's not ImageSharp nodes and without gatsby-image, the fragment is useless.
// Check if there are any ImageSharp nodes. If so add fragments for ImageSharp.
// The fragment will cause an error if there are no ImageSharp nodes.
const nodes = getNodes()

if (!nodes.some(n => n.internal.type === `ImageSharp`)) {
return
}

let gatsbyImageDoesNotExist = true
try {
require.resolve(`gatsby-image`)
gatsbyImageDoesNotExist = false
} catch (e) {
// Ignore
}

if (gatsbyImageDoesNotExist) {
return
}

// We have both gatsby-image installed as well as ImageSharp nodes so let's
// add our fragments to .cache/fragments.
// We have ImageSharp nodes so let's add our fragments to .cache/fragments.
await fs.copy(
require.resolve(`gatsby-transformer-sharp/src/fragments.js`),
`${program.directory}/.cache/fragments/image-sharp-fragments.js`
Expand Down

0 comments on commit 3389b89

Please sign in to comment.