Feature request: Ability to easily include / exclude additional files for babel-loader
See original GitHub issueThe default behaviour is that all of node_modules
is excluded from babel-loader:
In my case, I need to support IE11, and there is 1 package punycode
in node_modules that I need to feed into babel-loader, using the same babel config used on my app JS files.
The cleanest way I could get this to work was to dig into the source, copy-paste-tweak:
// webpack.mix.js
mix.webpackConfig({
module: {
rules: [
{
test: path.resolve(__dirname, 'node_modules/punycode'),
use: [
{
loader: 'babel-loader',
options: Config.babel()
}
]
}
]
}
})
While this works it felt a clunky, and that I was reaching into the internals a little bit. It got me thinking if there could be an easier way, some psudo code might look like:
// Don't pass any node_modules into babel-loader, default behaviour matching how it is now
mix.js('resources/js/app.js', 'public/js');
// Pass only "punycode" and "someotherpackage" packages files into babel-loader, ignore the rest of node_modules
mix
.options({
babelLoader: {
packages: ['punycode', 'someotherpackage'],
}
})
.js('resources/js/app.js', 'public/js');
// Override the default babel-loader test
mix
.options({
babelLoader: {
test: /\.(jsx?|tsx?)$/,
}
})
.js('resources/js/app.js', 'public/js');
I’m sure there there are many reasons why this API isn’t possible and probably needs more thought. But I think something like this could be useful as its come up at least a few times before:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Ability to easily include / exclude additional files for babel ...
In my case, I need to support IE11, and there is 1 package punycode in node_modules that I need to feed into babel-loader,...
Read more >Bountysource
Feature request : Ability to easily include / exclude additional files for babel-loader.
Read more >How to include node module for Babel using Webpack
I found it helpful to use the function for exclude as I was able to add console logs within the function to check...
Read more >babel/preset-env
@babel/preset-env takes any target environments you've specified and checks them against its mappings to compile a list of plugins and passes it to...
Read more >TypeScript - webpack
In this guide we will learn how to integrate TypeScript with webpack. Basic Setup. First install the TypeScript compiler and loader by running:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I wrote an extension to configure which npm packages get compiled by babel. Might solve your problem. See laravel-mix-transpile-node-modules.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.