-
-
Notifications
You must be signed in to change notification settings - Fork 451
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 modules: false
by default for es2015/env/latest presets
#529
Conversation
Override shouldnt be done with true but with a module type to match the mentioned presets options |
@SpaceK33z should I abandon my PR? |
@wardpeet, yeah this would make your PR redundant. Sorry about that, but I did end up using much of your code! |
@SpaceK33z no worries, thought it did the same as my PR 👍 |
I would be still in favor of showing a warning similar to |
src/index.js
Outdated
@@ -152,6 +152,34 @@ module.exports = function(source, inputSourceMap) { | |||
options.sourceFileName = relative(options.sourceRoot, options.filename); | |||
} | |||
|
|||
if (this.version > 1 && options.presets) { | |||
const presetsWithModulesOption = ["es2015", "env", "latest"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const presets = [ "es2015", "env", "latest" ]
// not sure if really needed (?)
const name = (name) => name
.replace(/^@babel\//, "")
.replace(/^preset-/, "")
options.presets.forEach((preset) => presets.indexOf(name(preset[0])) > -1
? preset[1] !== undefined
? preset[1].modules = false
: preset[1] = { modules: false }
: preset
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guys, what is the status of this PR? |
I messed up this PR by using force push, so I made a new PR #650. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
See #521.
What is the new behavior?
The Babel presets
env
,latest
andes2015
will be mutated to addmodules: false
as an option. This also works when you use e.g.@babel/preset-env
or@babel/env
.Does this PR introduce a breaking change?
For people who use babel-loader without setting the
modules
option, there might be small differences in the way webpack handles ES modules.For people who still want to keep the old behavior, they can explicitly add
modules: true
or e.g.modules: "amd"
.Other information:
I am not happy at all with the implementation, but it works. Let me know if there is a better way I missed.
I used parts of the code in #485, so credits to @wardpeet!
Fixes #521, fixes #477, fixes #485