Not really, but to be clear, I didn’t replace spago bundle
with ESBuild; I used them together. To be more specific, in development I would just run spago build
then use esbuild
to bundle them, while to build in production mode, I would run spago bundle-app
and then run the resulting file through esbuild
for the NPM dependencies, minification, and other stuff.
Here’s the command that I used in development (with irrelevancies stripped away):
spago build && esbuild src/index.js --bundle '--define:process.env.NODE_ENV="development"' --outfile=dist/index.js --format=iife
Where src/index.js
would be:
import { main } from '../output/Main';
main();
I’m not going to explain the commands, since I think they’re fairly understandable without an explanation.
Note: I can’t really remember if the format
argument and NODE_ENV
definition are necessary.
If you want file watching, ESBuild doesn’t have it built-in AFAIK, but with its insane performance, I think you can do something like this just fine:
spago build -w --then "esbuild src/index.js --bundle '--define:process.env.NODE_ENV=\"development\"' --outfile=dist/index.js --format=iife"
On to the production command:
spago bundle-app -t dist/index.unminified.js && esbuild dist/index.unminified.js --bundle --minify --format=iife '--define:process.env.NODE_ENV=\"production\"' --outfile=dist/index.js && rm dist/index.unminified.js
Again, not sure why I added format
.
If you have any questions, face any difficulties, or think I made a mistake, feel free to tell me.