I know cross file constant folding is not supported since that only happens in the first stage where esbuild optimizes each file separately and links them later. I'm openning this issue just to notify that because of svelte using esm-env, its development code won't be tree-shaked in esbuild.
Usually packages use hard-coded process.env.NODE_ENV check to separate dev codes, like Vue, which works fine with esbuild's define option. It's not svelte's fault to use esm-env, but that seems could only make rollup win in bundling svelte into production.
For reference, here's the test to bundle a hello-world svelte component:
I know cross file constant folding is not supported since that only happens in the first stage where esbuild optimizes each file separately and links them later. I'm openning this issue just to notify that because of svelte using
esm-env
, its development code won't be tree-shaked in esbuild.Usually packages use hard-coded
process.env.NODE_ENV
check to separate dev codes, like Vue, which works fine with esbuild'sdefine
option. It's not svelte's fault to useesm-env
, but that seems could only make rollup win in bundling svelte into production.For reference, here's the test to bundle a hello-world svelte component:
Let me explain the size a little:
DEV
variable and replacesif (DEV) { ... }
with{ ... }
or simpliy;
(empty statement).The final output size differs about 32 kB on the
svelte
module. It might be less when using more svelte features or building large websites.