Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a non starter for anything you want to publish online, as it breaks tree shaking which will cause size bloat and therefore slow loading.


I don't think this is true. The example from the esbuild docs uses `import * as lib from './lib.js'` in an example for tree shaking.

https://esbuild.github.io/api/#tree-shaking

Although there are associated issues but they may be specific to esbuild.

https://github.com/evanw/esbuild/issues/1420


Yes, as you pointed out, not only can bundlers tree shake namespace imports, but they're literally used in the esbuild documentation to demonstrate the concept of tree shaking.

The issue you linked to is referring to the case in which you import a namespace object and then re-export it. Bundlers like webpack and rollup (which vite uses in production) can tree shake this pattern as well, but esbuild struggles with it.

If you're using esbuild instead of this:

  import * as someLibrary from "some-library"
  someLibrary.someFunction()
  export { someLibrary }
You can still do this:

  import * as someLibrary from "some-library"
  someLibrary.someFunction()
  export * from "some-library"
  export { default as someLibraryDefault } from "some-library"
  
Tree shaking works as expected for downstream packages using esbuild in the second case, which someone else in the linked issue pointed out: https://github.com/evanw/esbuild/issues/1420#issuecomment-96...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: