你能在.babelrc中使用正则表达式吗?

Eva*_*bbs 9 javascript ecmascript-6 babeljs

这就是我的.babelrc样子.显然,由于JSON文件中的正则表达式,它不起作用:

{
  "presets": ["es2015", "react"],
  "plugins": ["transform-object-rest-spread"],
  "only": [
    '/client/**/*',
    '/server/**/*',
    /diy-fe-shared/ // <--- regex here breaks
  ]
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在这里使用正则表达式?

heg*_*ose 5

也许你可以.babelrc像这样使用正则表达式:https : //github.com/probablyup/markdown-to-jsx

创建.babelrc.js

const plugins = ['情感',];

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',
  ],
};
Run Code Online (Sandbox Code Playgroud)

然后要求.babelrc.js.babelrc

{
  "presets": ["./.babelrc.js"]
}
Run Code Online (Sandbox Code Playgroud)