Here's what my .babelrc
looks like. Obviously it doesn't work because of the regex in a JSON file:
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"],
"only": [
'/client/**/*',
'/server/**/*',
/diy-fe-shared/ // <--- regex here breaks
]
}
Is there a way to use a regex here?
Here's what my .babelrc
looks like. Obviously it doesn't work because of the regex in a JSON file:
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"],
"only": [
'/client/**/*',
'/server/**/*',
/diy-fe-shared/ // <--- regex here breaks
]
}
Is there a way to use a regex here?
Share Improve this question edited Jul 18, 2016 at 17:59 Evan Hobbs asked Jul 18, 2016 at 17:48 Evan HobbsEvan Hobbs 3,6726 gold badges33 silver badges45 bronze badges 6-
use the string
'/*/diy-fe-shared/**'
instead? – Patrick Roberts Commented Jul 18, 2016 at 17:51 - Please spellcheck your title. – user663031 Commented Jul 18, 2016 at 17:53
- Why would you need a regex here? Isn't a simple glob enough? – Bergi Commented Jul 18, 2016 at 18:15
-
@Bergi to be honest I'm not sure. the directory is in node_modules, ie.
node_modules/diy-fe-shared/
and it doesn't seem to work with glob matching but does with regex when I do it in javascript. Maybe something like babel ignores node_modules? – Evan Hobbs Commented Jul 18, 2016 at 18:24 - I'm surprised this question does not have a definitive answer yet. I'm also trying to find out! – Bill Commented Aug 30, 2017 at 9:09
2 Answers
Reset to default 5Maybe you can use regex in .babelrc
like this: https://github./probablyup/markdown-to-jsx
Create .babelrc.js
:
const plugins = [
'emotion',
];
if (process.env.NODE_ENV === 'production') {
plugins.push('transform-react-remove-prop-types');
}
module.exports = {
plugins,
presets: [
['es2015', {
loose: true,
modules: process.env.BABEL_ENV === 'esm' ? false : 'monjs',
}],
'react',
'stage-2',
],
};
Then require .babelrc.js
in .babelrc
{
"presets": ["./.babelrc.js"]
}
No, you cannot use regular expressions in .babelrc
files. But you can in .babelrc.js
files:
Rename your .babelrc
to .babelrc.js
and export your configuration object:
module.exports = {
"env": {
"production": {
"plugins": [/* Only run if webpack configures babel-loader's options.envName="production" */]
}
},
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"],
"only": [
'/client/**/*',
'/server/**/*',
/diy-fe-shared/ // <--- regex here works
]
};
https://babeljs.io/docs/en/configuration#babelrcjs