Menu

React on esbuild
📰

React on esbuild

DEV Community: esbuild·Artem Golendukhin·6 months ago
#LbdqVlGz
#dev#class#code#highlight#react
Reading 0:00
15s threshold

Usually we use create-react-app which does some magic behind the scenes like Webpack . Webpack is annoying, so let’s see how the app can work without it. I’ll try esbuild in this article instead.

We only need 3 packages:

yarn add react esbuild typescript

React is for components rendering

and esbuild to do all the magic instead of Webpack :

Transform jsx to JavaScript

Transform Typescript to JavaScript

Bundling all our code and node modules to one file

Simple http server to serve bundled index.js

So we don’t even need babel . I like babel , but esbuild already handles code transformation for us.

First of all let’s compile a command to use on yarn start:

./node_modules/.bin/esbuild index.tsx --bundle --outdir = . --servedir = . --loader :.js = tsx --watch

Where

—watch - to watch for changes so live reload is possible

--loader:.js=tsx - so esbuild understands and transforms Typescript

--outdir=. --servedir=. - to use a local esbuild http server. “.” - current path

Now let’s make index.html .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.