-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for proper ES module #30
base: master
Are you sure you want to change the base?
Conversation
Hey @niksy could you explain what this does or solves for you? My understanding is exports is for submodules/multiple entries but this only has 1 so the main/module should cover it. |
You’ve added Reproduction case:
{
"type": "module",
"scripts": {
"start": "node --input-type=module -e 'import \"./index.js\";'"
},
"dependencies": {
"viewprt": "^4.2.0"
}
}
import { ElementObserver, ObserverCollection } from 'viewprt'; Running
Applying changes from this PR will properly use module as ES module. This is probably nitpicking since Rollup and Webpack will use Current proper usage in ESM mode, without any changes, is as follows: import * as viewprt from 'viewprt';
const { ElementObserver, ObserverCollection } = viewprt This works, but doesn’t tree-shake |
Thanks for explaining @niksy. So it's native node support. However this is a browser only package and there is no bundling done by node where it would have tree shaking. I guess it doesn't hurt to add incase some bundlers start using it. Can it be done without creating the duplicate package.jsons? (and thanks for researching, I'm just trying to understand it). |
@gpoitch yeah, as I said, this doesn’t do anything for bundlers since they will take anything and resolve it to best possible case, but they already support it (see Rollup and Webpack related issues) so it doesn’t hurt to have package aligned with official specification. As for duplicate I will make changes to PR. |
This PR adds support for proper ES module configuration:
exports
field which references CommonJS and ES modulepackage.json
files with propertype
propertiesThis should probably be breaking change as explained in official documentation.