-
Notifications
You must be signed in to change notification settings - Fork 420
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
Include ES modules in NPM package #1300
Include ES modules in NPM package #1300
Conversation
Looks like Karma needs CommonJS babel plugin to run tests now that it's removed from |
I'm going to step back from this task for a week or so. All that needs to be done is to have the code that goes into Karma/PhantomJS to be CommonJS->UMD and ready for the browser. There's probably a way to configure webpack with ENV vars or turn Babel settings back into |
@davidlygagnon has offered to look into this issue. |
I'm thinking that it may just be easier to run the build/release process with This way we don't have to re-config our test runner right now. Here is the ES6 module build CLI command: |
Yeah, that's another option. How would consumer use |
We will still build a folder of ES6 modules, we just have to have Babel in ES6 output module when we build them. This can be done by overriding the Now that I've had it in the back of my mind for weeks, the problem with setting Babel to export as ES6 modules instead of CommonJS is that whatever consumes the post-Babel code has to understand ES6 modules--which is fine for most Webpack configs, but we are kind of dictating that with the preset in v2.0, and I think CommonJS as the default (consumers can always override a preset) which probably be better for the foreseeable future. |
To directly answer your question, the |
@davidlygagnon I'm transferring this issue to @futuremint since he said he was familiar with Bable transforms, etc. @futuremint We will need to release a 3.0 version of the babel preset that reverts |
Sure no worries. Sorry, haven't had much time to contribute in the last few weeks.. Hopefully soon. |
@interactivellama ok this is ready to review now. I tested this in Webpack 4 using the following minimal config:
And this as the JS file:
These results required the addition of I put my example repo here. |
…to interactivellama-es6-module-npm # Conflicts: # package-lock.json
Fixes #1284. Fixes #1269. Fixes #1265.
Additional description
Final solution was ES5 code wrapped in ES6 modules with
package.sideEffects = false
. This allows Webpack 4 to tree shake.Allows
package.module
to link to ES6 modules. This has been tested in the following ways:Uses ES6 modules package in:
Create React App with Webpack 3.
Does tree shaking with
Webpack 4
CRA 2.0 should use Webpack 4 and do the tree shaking.
Pull Request Review checklist (do not remove)
npm run dist
and inspect files.tmp-npm
into an existing project to see if it works.