Snowpack and GitHub Pages

Joel Malone
3 min readJul 28, 2021
Photo by Nikola Johnny Mirkovic on Unsplash

The problem

You use Snowpack to build a static website to be hosted on GitHub Pages, but your dependencies return 404.

This dependency doesn’t seem to exist… but whyyyyyy

The solution

Disable the Jekyll processing for your website by adding an empty file named .nojekyll to the website root.

The why

Snowpack bundles its dependencies into a folder named _snowpack, which is ignored by GitHub Pages. Why? Because GitHub Pages runs on Jekyll, and Jekyll ignores folders that start with an underscore.

So we need to tell Jekyll to not do that.

From About GitHub Pages in the GitHub Docs:

GitHub Pages will use Jekyll to build your site by default. If you want to use a static site generator other than Jekyll, disable the Jekyll build process by creating an empty file called .nojekyll in the root of your publishing source, then follow your static site generator’s instructions to build your site locally.

Snowpack is totally a static site generator! So we want to disable Jekyll as described, by adding an empty .nojekyll file to the website root.

See this completed example website, where the GutHub-hosted site is located at /docs, which has the .nojekyll file within it:

An example website built with Snowpack and hosted by GitHub Pages.

By adding the .nojekyll file, we are telling GitHub Pages to include our Snowpack dependencies.

But wait! There is one complication with how we add this file to our project.

The complication

In your Snowpack project, you probably have a folder named public that contains your static assets, which get copied into your build.

This is an ideal place to save your new .nojekyll file:

These files will be included as static assets in the build… except this one won’t

But when you do a build, this file is excluded from the build output!

By default, a Snowpack mount will ignore any files that begin with a dot, so we’ll need to tell it to include them in the builds by specifying dot: true, like this:

Tell Snowpack to include our new .nojekyll file

See the Snowpack docs for this and other mount configuration.

--

--

Joel Malone

Software Engineer living in Southwest Western Australia