visit
Learn how to contribute code to the open source project Gatsby
In Gatsby all projects are packages including Gatsby, plugins, and themes: It's a managed with .
At the end of this tutorial, you'll have a working local setup where you can test your changes to a Gatsby package.
Gatsby is one of the favorite static site generators right now. With more than 42.000 GitHub stars it's a major contributor to the . I would even say, one of their flagships.The and everybody is welcome to contribute to the project.If you encounter some problem while following this tutorial. Take a look
at the troubleshooting section, at the end of this post.
Let's start.
The Gatsby project itself, all his packages, and the contributors documentation use Yarn as the package manager ().
Clone the forked repo to your local machine.# clone the fork
git clone --depth=1 //github.com/<your-username>/gatsby.git
# go to gatsby
cd gatsby/
# install and build the projects
yarn run bootstrap
# check if everything works
yarn test
# check your current remote configuration
git remote -v
# configure the original gatsby repo as your remote upstream
git remote add upstream //github.com/gatsbyjs/gatsby.git
# check if the configuration has updated
git remote -v
# download objects and refs from the upstream
git fetch upstream
# integrate the upstream master into your local branch
git merge upstream/master
# create the branch where you're going to work
git checkout -b <feature-or-bugfix>/<feature-or-bugfix-name>
# create the branch where you're going to work
git checkout -b <feature-or-bugfix>/<feature-or-bugfix-name>
```
Create a symlink to a Gatsby package.
```bash
# change to the package directory (in this case a gatsby plugin)
cd packages/gatsby-transformer-remark/
# create the global symlink to the package
yarn link
# start watching the package files for changes
yarn watch
Add
console.warn(`HELLO_GATSBY_DEVELOPMENT`)
to gatsby-transformer-remark
.// in packages/gatsby-transformer-remark/src/on-node-create.js:16
// code...
const { createNode, createParentChildLink } = actions;
// Add the next line before the if:
console.warn(`HELLO_GATSBY_DEVELOPMENT`);
// We only care about markdown content.
if (
node.internal.mediaType !== `text/markdown` &&
node.internal.mediaType !== `text/x-markdown`
) {
return {};
}
// more code...
Gatsby CLI generated sites and the Gatsby end-user documentation use npm.
Open a new terminal and create a Gatsby test site.# install gatsby-cli
npm i -g gatsby-cli
# go back to your workspace directory
cd ../../../
# create a new gatsby site
gatsby new gatsby-test-site
# change directory into site folder
cd gatsby-test-site/
Link the Gatsby plugin inside
gatsby-test-site
.# link the local package (the package will not appear in your package.json)
npm link gatsby-transformer-remark
Add configuration to
gatsby-config.js
.// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {
// CommonMark mode (default: true)
commonmark: true,
// Footnotes mode (default: true)
footnotes: true,
// Pedantic mode (default: true)
pedantic: true,
// GitHub Flavored Markdown mode (default: true)
gfm: true,
// Plugins configs
plugins: []
}
}
];
Start the
gatsby-test-site
.gatsby develop
You should see the
HELLO_GATSBY_DEVELOPMENT
in the terminal.Congratulations! You have a working Gatsby environment. And you can start contributing to the open source project right now.
Find first-time friendly issues on the .You got questions or want to start a conversation? Contact me on or !By the way: don't forget to test and lint the package you're changing.
# from the root of the gatsby repo
yarn jest gatsby-transformer-remark
yarn lint
Happy coding!
gatsby develop throws errors
When executing
gatsby develop
on your gatsby-test-site
throws errors:gatsby clean
. If the problem persists remove node_modules
, and package-lock.json
and do npm i
To make it easier for the future add a script to your
package.json
.{
"scripts": {
"clean:npm": "rm -rf ./node_modules/ && rm ./package-lock.json"
}
}
Error: ENOSPC: System limit for number of file watchers reached
If you get a
System limit for number of file watchers reached
error, while watching files on a Linux distribution:Follow me on or .
If for some casual the indications did not work for you; . I'll update the post correspondingly.
Previously published at //rubenbelow.com/posts/contributing-to-the-gatsby-project/