We're hiring C/C++ and Zig engineers to build the future of JavaScript! See job listings →
This is the biggest release of Bun yet.
Bun now has a built-in JavaScript and TypeScript bundler and minifier. Use it to bundle frontend apps or bundle your code into a standalone executable.
We've also been busy improving performance and fixing bugs as-per usual: writeFile()
gets up to 20% faster on Linux, lots of bug fixes to Node.js compatiblity and Web API compatiblity, support for TypeScript 5.0 syntax, and various fixes to bun install
.
Bun's new JavaScript bundler & minifier
The focus of this release is Bun's new JavaScript bundler, but the bundler is just the beginning of a larger project. In the next couple months, we'll be announcing Bun.App
— a "super-API" that stitches together Bun's native-speed bundler, HTTP server, and file system router into a cohesive whole.
It can be used using the bun build
CLI command or the new Bun.build()
JavaScript API.
JavaScript
Bun.build({
entrypoints: ["./src/index.tsx"],
outdir: "./build",
minify: true,
// ...
});
CLI
bun build ./src/index.tsx --outdir ./build --minify
To learn more, check out our blog post introducing the Bun bundler.
Standalone executables
You can now create standalone executables with bun build
.
bun build --compile ./foo.ts
This lets you distribute your app as a single executable file, without requiring users to install Bun.
You can also minify it to improve startup performance for large apps:
bun build --minify --compile ./three.ts
[32ms] minify -123 KB (estimate)
[50ms] bundle 456 modules
[107ms] compile three
This is powered by Bun's new JavaScript bundler and minifier.
import.meta.main
You can now use import.meta.main
to check if the current file is the entry point that started bun. This is useful for CLIs to determine if the current file is what started the app.
For example, if you have a file called index.ts
:
index.ts
console.log(import.meta.main);
And you run it:
But if you import it:
And run it:
Improvements to bun test
bun test
now reports time taken to run tests
describe.skip
has been implemented (thanks to _yogr)expect().toBeEven()
andexpect().toBeOdd()
has been implemented (thanks to will-richards-ii)
Faster fs.writeFile
on Linux
Transpiler improvements
This release also introduces many improvements to the transpiler. Here are some of the highlights:
- Parser support for TypeScript 5.0.
- Parser support for import attributes.
- Some npm packages threw "ReferenceError: Cannot access uninitialized variable" errors on import due to a bug with cyclical imports in Bun's transpiler. This has been fixed.
- Support for
// @jsx
,// @jsxImportSource
, and// @jsxFragment
comments. - Dead code elimination for unused global constructor function calls like
new Set()
. - String template literal concatenation like
foo${1}${"2"}${'3'}
->foo123
. - Parser bugfixes for the deprecated ES5
with
statement.
A big thanks to @kzc for many helpful bug reports.
Node.js compatibility
tls.Server
has basic support (previously, not implemented)fs.promises.constants
is now exported correctly (previously, it was missing)node:http
's server module now (correctly) accepts acallback
argumentTimer.refresh()
now works as expected- Fixed
mkdtemp
andmkdtempSync
errors
Web API compatibility
new Request("http://example.com", otherRequest).url
would previously return the url ofotherRequest
instead of"http://example.com"
. This has been fixed.Bun.file(path).lastModified
has been added, which is similar to theFile
API'slastModified
property- Supported
redirect: "error"
infetch()
- Fixed
fetch.bind
,fetch.call
, andfetch.apply
not working
Changelog
Contributors
And finally, thank you to all the contributors from the community that helped improve Bun this release: @privatenumber, @Lawlzer, @jakeboone02, @zhongweiy, @xHyroM, @rmorey, @marktani, @Kruithne, @will-richards-ii, @simon04, @alexlamsl, @flakey5, @MaanuVazquez, @Plecra, @silversquirl, @beeburrt, @aquapi, @blackmann