Live data from Hacker News

Some notes on using esbuild

jvns.ca

21–30 of 205 posts

Re: Some notes on using esbuild

#21
post #16

If you're going to have a build step at all, instead of hand rolling your build commands and configs, just use Vite[1] already. It uses esbuild for development and rollup for production (since esbuild is not featureful enough for a lot of production use cases), you get instantaneous startup, hot module replacement, static asset imports, etc. for free. It's from Evan You, the creator of Vue, but it also supports React…

> instead of hand rolling your build commands and configs, just use Vite[1] already.

For greenfield projects? Certainly. For existing projects? Oh, you're in for a world of pain.

I'm all for breaking with the old and ushering the new era in, but there should be an upgrade path for as many possible combinations of the old as possible.

As luck would have it I decided to convert our project to vite to see if it's feasible.

So far it's:

- Absolute imports don't work and are broken in any number of subtle ways

We use typescript with a setup that resolves `/our-stuff` to `./src`.

Also this is served from `http://our-server/our-stuff` because we're a part of a larger app.

Good luck making this work with vite. Somehow it insists that you should replace all absolute imports with `/@/` and setup an alias for that. All other options (like using vite-tsconfig-paths) will not work because vite's `base` config will break this.

I "solved" it by listing all directories in `src` and converting them into vite aliases.

- Now I'm stuck with `[vite] Internal server error: failed to resolve "extends":"../../tsconfig.json" in /mui-theme/tsconfig.json`

How to fix it? Hell if I know.

At this point I'm just giving up, and looking into how to maybe upgrade to webpack 5.

Re: Some notes on using esbuild

#22
post #2

Esbuild is great. We couldn't fully migrate to esbuild due to some hard dependencies on webpack but we are currently using esbuild-loader which reduced our build times considerably.

You can also use the esbuild terser backend for minification. Almost halved the time of our release build

Do you have any information on how to do this? I've done a quick search but I wasn't able to find any relevant results.

EDIT: think I found it https://github.com/webpack-contrib/terser-webpack-plugin

Unfortunately, my project is still on webpack v4 so I cannot use this until I update.

Re: Some notes on using esbuild

#23
post #20
post #16

If you're going to have a build step at all, instead of hand rolling your build commands and configs, just use Vite[1] already. It uses esbuild for development and rollup for production (since esbuild is not featureful enough for a lot of production use cases), you get instantaneous startup, hot module replacement, static asset imports, etc. for free. It's from Evan You, the creator of Vue, but it also supports React…

I don't understand the point of vite. I tried using it and the "build" took over 30 seconds. esbuilds takes less than 1 second for the same project. > esbuild is not featureful enough for a lot of production use cases What makes you say that? I keep hearing people say this, but I haven't run into any problem that make esbuild not ready for production.

> I tried using it and the "build" took over 30 seconds.

It hardly matters because it's very rare that you need to run build during development. Use dev.

> I keep hearing people say this, but I haven't run into any problem that make esbuild not ready for production.

https://vitejs.dev/guide/why.html#why-not-bundle-with-esbuil...

Re: Some notes on using esbuild

#24
post #20
post #16

If you're going to have a build step at all, instead of hand rolling your build commands and configs, just use Vite[1] already. It uses esbuild for development and rollup for production (since esbuild is not featureful enough for a lot of production use cases), you get instantaneous startup, hot module replacement, static asset imports, etc. for free. It's from Evan You, the creator of Vue, but it also supports React…

I don't understand the point of vite. I tried using it and the "build" took over 30 seconds. esbuilds takes less than 1 second for the same project. > esbuild is not featureful enough for a lot of production use cases What makes you say that? I keep hearing people say this, but I haven't run into any problem that make esbuild not ready for production.

ESBuild doesn't transpile your code down to ES5.

If you're using any ES6 features - default params, template literals, arrow functions, let/const, spread, etc, your cut-off for browser support will be ~2017 (= no support for IE 11).

swc (https://swc.rs) does transpilation and it's as fast as esbuild. Setup is slightly more complex. I'm hoping esbuild will add ES5 transforms at some point, would much rather have a Go tool underneath.

Re: Some notes on using esbuild

#25
post #16

If you're going to have a build step at all, instead of hand rolling your build commands and configs, just use Vite[1] already. It uses esbuild for development and rollup for production (since esbuild is not featureful enough for a lot of production use cases), you get instantaneous startup, hot module replacement, static asset imports, etc. for free. It's from Evan You, the creator of Vue, but it also supports React…

> instead of hand rolling your build commands and configs, just use Vite[1] already. For greenfield projects? Certainly. For existing projects? Oh, you're in for a world of pain. I'm all for breaking with the old and ushering the new era in, but there should be an upgrade path for as many possible combinations of the old as possible . As luck would have it I decided to convert our project to vite to see if it's feasi…

Point taken, but it's not like switching the average existing webpack project (let alone a webpack 4 project) to esbuild is just a walk in the park. We're talking about whether you should roll your own esbuild commands here.

Re: Some notes on using esbuild

#26
post #20

Earlier quoted context omitted.

I don't understand the point of vite. I tried using it and the "build" took over 30 seconds. esbuilds takes less than 1 second for the same project. > esbuild is not featureful enough for a lot of production use cases What makes you say that? I keep hearing people say this, but I haven't run into any problem that make esbuild not ready for production.

ESBuild doesn't transpile your code down to ES5. If you're using any ES6 features - default params, template literals, arrow functions, let/const, spread, etc, your cut-off for browser support will be ~2017 (= no support for IE 11). swc ( https://swc.rs ) does transpilation and it's as fast as esbuild. Setup is slightly more complex. I'm hoping esbuild will add ES5 transforms at some point, would much rather have a G…

Plain esbuild is perfect for adding typescript support to node.js projects. We literally just run ’esbuild && node dist/run.js’

Re: Some notes on using esbuild

#27
post #16

If you're going to have a build step at all, instead of hand rolling your build commands and configs, just use Vite[1] already. It uses esbuild for development and rollup for production (since esbuild is not featureful enough for a lot of production use cases), you get instantaneous startup, hot module replacement, static asset imports, etc. for free. It's from Evan You, the creator of Vue, but it also supports React…

> instead of hand rolling your build commands and configs, just use Vite[1] already. For greenfield projects? Certainly. For existing projects? Oh, you're in for a world of pain. I'm all for breaking with the old and ushering the new era in, but there should be an upgrade path for as many possible combinations of the old as possible . As luck would have it I decided to convert our project to vite to see if it's feasi…

The sane option would be to use a codemod to rewrite your code to not need bespoke tooling configurations. You are locking yourself into legacy tooling.

Re: Some notes on using esbuild

#28
I find it fascinating that there are people still using script tags. I have personally become so tied to npm and typescript that it feels that I'm programming in a completely different language and ecosystem, with a build process and IDE-like type checking and linting, a more procedural data-oriented C-like paradigm.

I've never touched the old JS guts, `module.exports`,the prototype chain, ... Babel (and later TypeScript) allowed me to live in ESM land from the beginning. I expect any tool/library to be available using exclusively on npm, in reality, I've been constantly fighting with it over the past few years.

I usually get a shock when I see libraries still offering minified bundles that assign to the global namespace, to me this seems like outdated practice, but I guess that this is still really prevalent in JS, even in 2021. I sometimes want to go back to it, with the amount of configuration and boilerplate necessary to set up a project with npm, Prettier, ESLint, Typescript, Webpack/Parcel/Rollup, SPA vs MPA, React vs Vue vs $SPAFRAMEWORK, it was a lot easier back in the day.

I think the biggest failure in the JS system is the lack of standardisation, it's so versatile that almost anything is possible. A number of different module systems were invented to solve the initial growing pains (the first would literaly replace a `require()` function call with the contents of the given file), and we never escaped them as they became the foundations of Node.js/npm. Then we needed a non-blocking variant, so we just called it `import()`, it returns a promise. Then we wanted proper imports, so we invented the `import ... from ...;` ESM syntax. We made a named import and default import variant (with most bundlers offering a compatibility layer with CJS-type exports, so imports now have a hidden `__esModule: true` key...). In order to stay compatible with legacy CJS, we also added the `import * as ... from ...;` syntax as an escape hatch?

When TypeScript came along, in order to be compatible with JS it became common practice to distribute compiled TS code along with the source code, with an adjacent declaration `.d.ts` file to provide type information. The source code was never leveraged in any way, and so people just stopped shipping the `src` directory, only `dist` and a `package.json`. It makes debugging a pain, but compiling TS libraries would have been tricky, considering the widely varying different feature flags (async, DOM, ...) and strictness options. Perhaps Deno will help with this to some regard. The great thing about Go or Rust (or any other language, really) is that you import source code, not illegible compiled code (unless you're dynamically linking). I believe that Rust is especially good in this regard, it remains compatible with older code by requiring crates to specify a Rust "edition".

Why are we in this mess in this first place?

And why has it remained so darn popular?

Re: Some notes on using esbuild

#29
post #10
post #5

If you want to keep things simple while using packaged libs, there's no need for a build step. You can import ES Modules directly in a script by using URL as module name. Use e. g. ESM.sh as the registry, most NPM packages are available.

this does not fulfill the requirement of her: 'I could fix them when they break'

I'd prefer monkeypatching instead of modifying minified and/or compiled code.

Re: Some notes on using esbuild

#30
> problem 1: libraries that tell you to npm install them

Agreed. I wish `npm install` was just some option for those who wanted it. But no! Somehow it became the defacto standard and everyone just expects everyone else to already be onboard.

I got onboard reluctently because that's the only way to use the libraries I cared about.

> problem 2: I don’t understand frontend build tools

Absolute and total agreement.

I can't agree enough.

I think no one really understands them.

> “webpack” which I will not try to explain much because I don’t understand it, I think it’s a system with a million plugins that does a million things

I haven't worked with anyone who understood webpack. They just use a scaffold-builder to set it up in a pre-configured way and then you just never touch it.

> Recently I learned about esbuild which is a more Unix-style tool.

esbuild is the best thing that happened to frontend development. It finally freed us (well, me anyway) from the messy js build systems.

But I'd like to strongly object to describing it as a "unix-style" tool. Unix style tools to me are tools that deal with plain text and expect you to pipe them with other tools to get the job done. esbuild is nothing like that. It's the entire build pipeline in one tool. You don't work with it by piping its inputs and outputs to other tools. It provides you a programming interface and you write code to make it do what you want.

EDIT:

To clarify, I think it's a very good thing that esbuild is not a unix-style tool. I know the common wisdom on HN is in favor of the unix philosophy, but I don't buy into that.

Post reply on HN