-
-
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
How to handle npm modules which include es6 #171
Comments
Any word on this? |
@eoinmurray you can exclude all node modules except qs using the following: exclude: /node_modules\/(?!qs)/ This will let babel transpile qs without touching every other node module. If you need to exclude more than one module you can extend the exception list like so: exclude: /node_modules\/(?![module1|module2])/ Hope that helps :) |
This is great thanks, totally solves the issue! |
see babel/babel-loader#171 for details
Above second regex didn't work me. Regex for including multiple modules, that worked for me, is: exclude: /node_modules\/(?!(module1|module2)\/).*/ thanks @jonnymbgood for the right pointers though! |
|
It looks like perhaps this has since been fixed in But for future reference, I've created a webpack helper to automatically detect dependencies such as this one that may require Babel transpilation. See https://github.com/andersdjohnson/webpack-babel-env-deps. It should work if a module specifies |
I've struggled with this also and this solutions, adding the exclude negative lookahead didn't solved my problem, but 50% of it. I had to add to the include as well.. For ex.
|
we should use not sure if this is a feature or a bug |
For your information, there's a plugin that may help simplifying things: next-plugin-transpile-modules |
You could use an array for the dependencies, it's a little nicer to edit this way. And you don't have to escape module names. const transpileDependencies = [
'module1',
'module2'
]
loaders: [
{
exclude: new RegExp(`node_modules/(?!(${transpileDependencies.join('|')})/).*`)
}
] |
I know I've compiled node_modules in the past using something like the above methods that use exclude. They weren't working for me this time, as of babel 7 which seems to ignore node_modules automatically This worked:
|
If anyone's still confused by changes in Babel 7 (I was), you have to switch to using |
works!!!!!!!!!! |
If you're experiencing this issue with Next.js, use |
What if the package that should be transpiled contains its own node_modules package that should be transpiled as well? How it can be handled? Project (Babel/Webpack/Typescript)
|
worth mentioning is that (for me at least) the build time was much quicker, especially in watch mode with webpack when using only include and not even bothering with exclude. node_modules seems to be ignored by default, and simply explicitly including what you need to be transpiled instead appears to be faster:
|
So my code is like this: const modulesToTranspile = ['module1', 'module2', '@corp/long-module-name'];
// webpack config
include: modulesToTranspile.map(moduleName =>
path.resolve(__dirname, `../../../../node_modules/${moduleName}`)
),
exclude: [new RegExp(`node_modules\/(?!(${modulesToTranspile.join('|')}))`)] |
The docs state it very clear: https://webpack.js.org/configuration/module/#condition |
This is my babel-loader import in my
webpack.config.js
fileI try to run this to make minified code with
webpack -p --config webpack.config.js
It works fine unless I have the module qs.js included, which uses the keyword
let
throughout.The authors of
qs.js
recommend transpiling qs using babel ljharb/qs#141.I achieved this in the compilation step by removing
exclude: /node_modules/
but I think thats messy as it babelify's every module included in my application.Is there a more elegant way to do this, without needed to manage my own version of
qs.js
The text was updated successfully, but these errors were encountered: