I have created a seed application for people who are interested in exploring Bazel as the single build tool for Svelte applications.

Bazel?

First of all, what is Bazel? Good question! For more context on Bazel I recommend reading my previous article if you are new to Bazel.

Seed Application

The seed application is still experimental, but it currently contains working examples for both a dev environment and a production build.

The actual Bazel rules for Svelte are available in a separate repo if you are interested in setting up your own repo.

Dev Build

The Dev build supports the usual features developers have come to expect from a dev environment. It launches in a browser which refreshes automatically for every source code change. Under the hood it uses lite-server as the dev server and rollup for bundling. It’s all wrapped by Bazel, so the only command you need is yarn start-dev to kick things off.

Prod Build

The production build creates a production ready Svelte artifact. It also launches a Node/Express application that can be used to host your Svelte application. In addition to the Express host I have also added support for creating a Docker image from the prod application. Just run yarn create-docker-image.

The docker image can optionally be pushed to a docker registry like Dockerhub by running: yarn push-docker-image.

The Docker workflow is managed by Bazel, so it will work even if you don’t have Docker installed. That said, the Docker part currently only works on Linux, but in a CI-CD workflow this should be fine in most cases.

How to run it?

After cloning the repo all you need is a yarn install.

Bazel is now available from npm, so it’s no longer necessary to install Bazel separately. Since Bazel is a large download, the install may take slightly longer than normal.

Next, run either yarn start-dev or yarn start-prod for dev or prod environments respectively.