-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
how babel-loader deal with ES6 import? #138
Comments
I met the same question. When I use dynamic import in babel-loader, error happened: "unexpected token" at the import(). |
I got the answer. https://babeljs.io/docs/plugins/preset-env/#optionsmodules |
Ok, the default seems to be Isn't this sub-optimal for Webpack 2 tree shaking feature? See also: https://medium.com/@johnstew/webpack-tree-shaking-20914b7a9ca5 |
@gimmi With CJS Modules there isn't any 'tree-shaking' :). You need to explicitly disable module transpilation via babelrc {
"presets": [
[
"env", {
"targets": {
// specify supported browsers (ES2015+ Features to transpile)
"browsers": { "chrome": 60 }
},
// no module transpilation to CJS (!important)
"modules": false
}
],
// if you use React (JSX)
[ "react" ]
],
"plugins": [
// Syntax support only so babel doesn't complain, no transpilation
"syntax-dynamic-import"
],
"env": {
"test": {
// Only for testing components (NODE_ENV = 'test') in NodeJS, which needs CJS to work
"plugins": [ "transform-es2015-modules-commonjs" ]
}
}
} |
Does babel-loader just leave the import tasks to webpack? Any difference between babel-loader in webpack and the babel tool alone in node CLI?
The text was updated successfully, but these errors were encountered: