Export ESM
See original GitHub issuegetstream
is currently exported as UMD only. ESM support has been around in NodeJS (and the browser) for some time and, I believe, since v12.20 it can be used without a flag. With NodeJS 16 being LTS at the time of this writing, I think it would be nice to provide an ESM export. The main advantage (for me, anyway) would be to use the same syntax when importing from a CDN and node_modules
, rather than using a global variable.
Further reading:
- https://medium.com/swlh/npm-new-package-json-exports-field-1a7d1f489ccf
- https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77
- https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
While I don’t want to get too specific on my own code, I would like to provide an example where this would help developers. When using Vite’s development server, I can’t import getstream
from without running into NodeJS-specific problems (this issue is possibly related). The same import works fine when Vite builds my code and optimizes it for the browser. Currently, my only workaround is to change the import from import stream from "getstream"
to import "https://cdn.jsdelivr.net/npm/getstream@8.0.0/dist/js_min/getstream.js"
. However, I need to undo this change whenever I build, since I want to import the locally installed npm package of getstream
. If you provided an (browser-optimized) ESM, I could simply put a condition on NODE_ENV
in my config file (example below), not rewriting my import on every switch between development and build.
resolve: {
alias: {
"getstream": process.env.NODE_ENV ? "https://cdn.skypack.dev/getstream" : "getstream"
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Hi! Any updates?
@oski646 @bradintheusa - did you have a chance to test that?