oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.26k stars 2.77k forks source link

bun's bundle is about twice as large as esbuild's one #4928

Open m4r-v1n opened 1 year ago

m4r-v1n commented 1 year ago

What version of Bun is running?

1.0.0

What platform is your computer?

Darwin 23.0.0 x86_64 i386

What steps can reproduce the bug?

// src.js

import { w3mConnectors, w3mProvider } from '@web3modal/ethereum'
import { Web3Modal } from '@web3modal/html'
import { configureChains, createConfig } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'

const chains = [mainnet]
const projectId = '_PROJECT_ID_'

const { publicClient } = configureChains(chains, [w3mProvider({ projectId })])
const wagmiConfig = createConfig({
  autoConnect: true,
  connectors: w3mConnectors({ projectId, chains }),
  publicClient
})
const ethereumClient = new EthereumClient(wagmiConfig, chains)
const web3modal = new Web3Modal({ projectId }, ethereumClient)
$ esbuild src.js --bundle --minify --outfile=out.js

  out.js  822.6kb  👈

âš¡ Done in 87ms
$ bun build src.js --minify --outfile=out.js

  out.js  1554.10 KB  👈

[107ms] bundle 722 modules

What is the expected behavior?

out.js should be about same size.

What do you see instead?

esbuild's out.js is 822.6 KB bun's out.js is 1554.10 KB

fregante commented 1 year ago

Could be unrelated, but I noticed that bun does not treeshake some functions. In my case (a plain bun build file.js), minify will preserve the bun-injected __require function that isn't used anywhere. I'm removing it with bun build file.js | sed 's/import.meta/{}/' 😅