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?
.babelrc.json or .babelrc files are loaded relative to the file being compiled. If this option is omitted, Babel will behave as if babelrc: false has been set. Used as the default value for Babel's sourceFileName option, and used as part of generation of filenames for the AMD / UMD / SystemJS module transforms.
If this option is omitted, Babel will behave as if babelrc: false has been set. Used as the default value for Babel's sourceFileName option, and used as part of generation of filenames for the AMD / UMD / SystemJS module transforms.
Babel loads .babelrc.json files, or an equivalent one using the supported extensions, by searching up the directory structure starting from the "filename" being compiled .babelrc would be useful if you want to run certain transformations / plugins on a subset of files /directories.
Babel will look for a .babelrcin the current directory of the file being transpiled. If one does not exist, it will travel up the directory tree until it finds either a .babelrc, or a package.jsonwith a "babel": {}hash within. Use "babelrc": falsein optionsto stop lookup behavior, or provide the --no-babelrcCLI flag.
Maybe you can use regex in .babelrc
like this: https://github.com/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 : 'commonjs',
}],
'react',
'stage-2',
],
};
Then require .babelrc.js
in .babelrc
{
"presets": ["./.babelrc.js"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With