Publish a Gatsby Theme to npm

Jason Lengstorf
InstructorJason Lengstorf
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

Make your Gatsby theme available for use by anyone in the community by publishing it as an npm package.

For a written version of this course, check out the Gatsby docs.

Instructor: [00:00] To publish our theme, we need to update a couple of things in package.json. The most important one is that we want to name space our theme. This helps us keep track of who publish it, and it also helps avoid naming collisions.

[00:15] Once we've got our theme name space, we need to make sure that we're logged in to npm. We can check this by writing npm whoami. If we're not logged in, it's going to tell us that we need to be logged in and how to do it. We can run npm add user. It's going to ask me for my user name and a password. I have to fill in my email.

[00:47] Now that I am logged in, if I run npm whoami, it shows me that I am Jay Lengstorf. With the theme name spaced, and me logged into npm, I am ready to publish. I can change directories into the Gatsby theme event directory. I can run npm publish, and because it's name space, I need to include access public.

[01:12] Now, it's published. After publishing, we'll be able to find our theme up on npm at and the name of our theme.

Samuel Suther
Samuel Suther
~ 4 years ago

What is the recommended way to have a workspace which directly use such "scoped" theme-packages? I've found that it is not that easy to make this work. Do you have any suggestion how to archive this, or do you only recommend to change the package.json name to a scoped one before uploading it to registry, and after that rename it back?

Jason Lengstorf
Jason Lengstorfinstructor
~ 4 years ago

with workspaces, you can still use scoped packages. for example, if you name a package @egghead/party, you could run its develop script with yarn workspaces using:

yarn workspace @egghead/party develop

is that what you're asking? if not, let me know what you're trying to achieve and we'll get it figured out. thanks!

Samuel Suther
Samuel Suther
~ 4 years ago

Ok, I've solved it now. Thanks a lot.

Markdown supported.
Become a member to join the discussionEnroll Today