How to add live reload to esbuild server
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
No comments yet. Be the first to comment.
In this series, I'll show simple but complete application set-up with esbuild.
In this article, I'll show you how to add a source map to the setup we developed so far in this series. What is source map As we introduce any bundling or compiling step to our application, we start to have a difference between what's in our source c...
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

In this article, I'll show how to set up a complete development server for esbuild. It's a replacement for the half-successful approach I had in the previous post.
This approach is based on esbuild-serve - a nice package that allows us to support two main use cases: building & development server. Let's install it first:
$ npm install esbuild-serve -D
> esbuild@0.9.7 postinstall /home/marcin/workspace/github/esbuild-tutorial/node_modules/esbuild-serve/node_modules/esbuild
> node install.js
+ esbuild-serve@1.0.1
added 3 packages from 1 contributor and audited 4 packages in 1.901s
found 0 vulnerabilities
The configuration file we will use is a combination of the one developed in the previous post and the one presented in the esbuild-server documentation. esbuild.config.js:
#!/usr/bin/env node
import esbuildServe from "esbuild-serve";
esbuildServe(
{
logLevel: "info",
entryPoints: ["src/index.js"],
bundle: true,
outfile: "www/main.js",
},
{ root: "www" }
);
We can run this file with:
node esbuild.config.js - for buildingnode esbuild.config.js -w - for development serverIf you run those scripts and get:
$ node esbuild.config.js
(node:86676) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/marcin/workspace/github/esbuild-tutorial/esbuild.config.js:3
import esbuildServe from "esbuild-serve";
^^^^^^
SyntaxError: Cannot use import statement outside a module
...
as I did, you will need to add to package.json:
{
...
"type": "module",
...
Now, the final step is to replace the old npm scripts with calls to the current one:
{
...
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node esbuild.config.js",
"start": "node esbuild.config.js -w"
},
...
And it's working as expected:
$ npm run build
> esbuild-tutorial@1.0.0 build /home/marcin/workspace/github/esbuild-tutorial
> node esbuild.config.js
www/main.js 151b
www/main.css 44b
⚡ Done in 2ms
$ npm run start
> esbuild-tutorial@1.0.0 start /home/marcin/workspace/github/esbuild-tutorial
> node esbuild.config.js -w
[watch] build finished, watching for changes...
Serving 🍛
Local → http://localhost:7000
Network → http://192.168.2.107:7000
You can check out my video course about esbuild.
We have seen how to set up a development server for esbuild. This setup has live reload & it's ready to use esbuild plugins. If you are interested in hearing when I have new esbuild content, you can sign up here: