ESBuild は minify 時に関数を inline 展開しない
takker.icon の scrapbox bundler は ESBuild でビルドしているので、 scrapbox bundler も inline 展開しない
これは ESBuild 自体の高速化のため
なんか AST をもう 1 回構築する必要があるから止めたとか
natemoo-re
Hello there! I know minification isn't the core focus of esbuild, but one very nice feature of terser is identity function inlining (see terser#510.) It would be nice if esbuild could optimize these functions away as well, as it's a pretty common pattern. code:input.js
const id = x => x;
console.log(repro);
code:Current output.js
code:Desired output.js
const repro=1,2;console.log(repro); どうでもいいけどコレ実際のコードじゃなさそうSummer498.icon
minify かけたら変数名が e, t, n, ... になるから
evanw
his isn't super straightforward to fix because doing this correctly would require inserting at least one more full-AST traversal after the scanning phase but before the linking phase. This would slow esbuild down and would work against the goal of having as few passes as possible for speed. So I'm not planning on having esbuild tackle these kinds of optimizations. At least not at the moment.
Another consideration is that the author of Terser is currently exploring a rewrite in Rust which should hopefully alleviate the huge performance impact of running Terser during a build. If that rewrite is successful, it might make less sense for esbuild to do all the work to replicate the advanced optimizations that Terser does if people can just run Terser after running esbuild instead.
Another similar request: #290. natemoo-re
That makes total sense, thank you for the quick and thorough response. As the docs mention, esbuild's minification is definitely within range of the alternatives—was just curious if this would be a quick optimization!
Going to close this as it seems out of scope for now.
evanw
I implemented this for function declarations by the way. It was not a quick optimization, and it's a bit of a hack, but it should work now. See #1898 for details.