niksy / node-stdlib-browser

Node standard library for browser.
MIT License
188 stars 13 forks source link

Vite could not build node-stdlib-browser into correct iife lib, but umd/cjs/esm is correct #27

Closed zouhangwithsweet closed 1 year ago

zouhangwithsweet commented 1 year ago

Reproduction

https://stackblitz.com/edit/vitejs-vite-qiftgb?file=main.js

reference: https://github.com/vitejs/vite/issues/12872 And they found that if this line is commented https://github.com/niksy/node-stdlib-browser/blob/master/index.js#L10, the dist's syntax will be correct.

I hava not idea about that

zouhangwithsweet commented 1 year ago

Maybe this issue doesn't need to be fixed. I just use umd.

niksy commented 1 year ago

I don’t think this has anything to do with this plugin, but how Vite handles final file optimization. The line that is mentioned is used to properly resolve location of module to use and needs to be used here.

You are correct in that UMD output produces what you required. What I also found that works is you you export any type of content, e.g.

// …
// init stream
export default (() => {
  setupPageStream();
})();

This will properly produce IIFE output with ringsOutput library name.