-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
RFC - Dealing with imports/exports #23
Comments
I'll tweak the babel config |
The only viable answer is to transpile it down into ES5 and pray to the NodeJS gods that they sort out the ES Module thing finally so we can stop using |
Yeah. I saw a blog post month ago where the ETA was a year. I think the plan is to end up with I think the only thing that remains is figuring out how to deal with |
Sticking this here for reference output of the current Babel configuration ..
|
My only worry is CommonJS/ES6 interop. I mean this (repl against file-loader webpack-defaults PR):
It would be good to ask Henry or someone in the know to figure out the right way to handle this. |
We can just as easily use a named export though that really doesn't make any sense. And interop with what exactly? From what I can read, Webpack handles export default just fine. |
Yeah, named export wouldn't work either.
Webpack side isn't a problem as it's easy to manage there. If we go with defaults, that's a breaking change for those that consume functionality standalone for reason or another. But that can be handled through a major version bump and if you consume loaders/plugins outside of webpack, you can always do |
So rule number 1, an upgrade to defaults is a semver To that end, we should not release any majors in contrib so no loaders / plugins get them back to back which just screams poor planning. Rule #2, every major gets at least on
|
Major bump + clear communication sounds like the way. The worst thing that could happen is that someone on webpack 1 installs a package without knowing about the change. It's an instant error unless the an adapter against Beta sounds fair too. |
I sent Henry a message on Slack, before we start propagating this to everything in the Org he has recommended asking @loganfsmyth & @kovensky for their advice. |
Is there a quick summary of what you're changing? I don't think I have enough enough context in the conversation here. |
@loganfsmyth It's about loader/plugin packaging. Currently most, if not all, use CommonJS (no preprocessing). With the advent of webpack-defaults we are changing things around. Now distribution code will be processed through Babel. The question is, what's the standard way of dealing with exports in this case assuming you are transpiling from ES6 module definition? |
You'd be distributing CommonJS modules that have been output by the ES6 module compilation step in Babel, got it. I think the most important thing to remember is that the interop story between CommonJS and real ES6 modules is going to be up in the air for a while, as you mentioned above. We can make guesses about it, but at the end of the day the CommonJS interface is king, with Babel's interop if you happen to use Babel's compiled As you've said, Babel's standard approach is to define a property for each export on the Another alternative that many people use is Alternatively, you could always run the files through Babel but continue to use CommonJS directly, disallowing usage of ES6 imports/exports. I'd say it kind of depends on the usecase. A lot of people like |
The simplest and cleanest would be leaving ES2015 Module transpilation out for the moment Loaders/Plugins are targeting node where CJS will be the recommended module system for some time and two+ active LTS are CJS only regardless of what may come in the near future (approximately 1 year) in terms of ES2015 Modules in node |
This whole topic has been discussed since 2013 and quite frankly, it's time for the community to stop sitting on their hands and get on with this. The language is evolving, everyone simply needs to accept that and evolve along with it. It is our responsibility as one of the larger organizations in the JavaScript ecosystem to both support the efforts to advance the language and support other organizations like Babel who do so every day. The priority here is to ensure we are compatible with Webpack, then our other loaders / plugins ( to include the AngularCLI ) & lastly the libs that We are fine with Webpack, have direct control of the second and as far as the last priority, we can proactively convey the change to those libs to include going so far as to pull request in the required updates for the next majors beta tag. When you distill all of this down, in a CommonJS environment we are really talking about someone having to add a
@loganfsmyth - Thanks for taking a minute to give us your |
Soap box speeches aside, i'm on the fence with all of this for one simple reason...
So why don't we split the difference, use Upgrading to |
I'd recommend against using If you want to shield your users from having to use An alternative is to do something like the following:
For example, if your entry point is {
"module": "./index",
"main": "./cjs"
} And then put this in the module.exports = require('./index').default This unfortunately won't be usable with real modules (either you won't be able to |
Yeah, I would be inclined to go with @Kovensky's way. A proxy would allow us to use ES6 modules internally. When the time comes, we can refactor the proxies out. The coolest thing is that the users won't notice the change unless they happen to refer to code outside of the formal interface. That's actually a potential problem for webpack core as people seem to point below |
I'm fine with that as well. I'd certainly prefer to use ES modules, doing so without having to deal with the onslaught of X doesn't work anymore is a definite bonus. Unless someone strongly objects, lets go that route and get file-loader updated. We could put the proxy in @bebraw When you get a chance, make file-loader look the way you want it & i'll update the babel config ( if necessary ) and PR in the template updates to defaults. |
@d3viant0ne Done. We should probably make the following changes to webpack-defaults:
|
Context: webpack-contrib/file-loader#130 (comment)
If webpack packages use
import
/export
semantics and don't transpile, we'll end up with issues like this:The problem is that if we do
export default something
, then that will lead to the.default
issue with CommonJS environments.Any ideas on a clean way to handle this? Maybe packages should use ES6 style internally and expose their public API through a CommonJS
module.exports
?The text was updated successfully, but these errors were encountered: