Reputation: 554
I just upgraded to babelv7 , earlier I had a default environment which had some aliases and a test environment which had some aliases, now in the test environment babel used to merge both the configs, in babelv7 this functionality has been removed ,how to achieve this merging functionality without repeating the aliases 2 times.
This is my babel.config.js
module.exports = {
presets: ['custom-preset'],
env: {
test: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
'transform-class-properties',
[
'module-resolver',
{
root: ['./app'],
alias: {
'test-util': './node_modules/test-util/lib',
},
},
],
],
},
},
ignore: ['node_modules'],
plugins: [
[
'transform-imports',
{
lodash: {
transform: 'lodash/${member}',
preventFullImport: true,
},
},
],
[
'module-resolver',
{
root: ['./app'],
alias: {
'module1': './src/components/module1',
},
},
],
],
};
Upvotes: 0
Views: 478
Reputation: 161517
The primary change to merging in Babel 7 is that things are actually merged more, so instead of this config producing two instances of module-resolver
with two different configs, the one in test
will overwrite the config for the module in the top-level.
To tell Babel that they are meant to be two independent plugins, you need to give at least one of them a unique name, which is a string passed as the third entry in the plugin item array, e.g.
plugins: [
'transform-class-properties',
[
'module-resolver',
{
root: ['./app'],
alias: {
'test-util': './node_modules/test-util/lib',
},
},
'testing-resolver' // A name for the plugin so it is unique and doesn't overwrite
],
],
Upvotes: 1