This plugin allows you to source the contents of package.json
.
npm install --save gatsby-source-package
or
yarn add gatsby-source-package
Add the plugin to gatsby-config.js
..
module.exports = {
plugins: [...`gatsby-source-package`],
};
You may only source some of the keys in package.json
:
module.exports = {
plugins: [
{
resolve: `gatsby-source-package`,
options: {
only: ['name', 'version', 'description'],
},
},
],
};
The GraphQL query will match your package.json
:
query {
package {
name
version
description
}
}
Result:
{
"data": {
"package": {
"name": "gatsby-starter-hello-world",
"version": "0.1.0",
"description": "A simplified bare-bones starter for Gatsby"
}
},
"extensions": {}
}