javascript - webpack 忽略 .babelrc 和 babel.config.js

我正在使用 webpack 4.32.2 和@babel/core 7.2.0

我的 webpack 配置位于此处

projectroot/build/webpack.config.js

当我运行我的 webpack 配置时,一切正常,除了我的 babel.config.js,它位于这里

projectroot/babel.config.js

只是被忽略了。

我用也是一样

projectroot/.babelrc

这些文件似乎都不重要。

这是 webpack.config.js 中的 babel loader 部分的样子(注意我添加了 rootMode: 'upward' 指令以确保找到任何上述目录中的任何 .babelrc 或 babel.config.js :

{
  test: /\.js$/,
  loader: 'babel-loader',
  exclude: /node_modules/,
  options: {
    rootMode: 'upward'
  } 
}

我希望能够使用 babel.config.js,但如果有问题,我也会使用 .babelrc。目前没有一个被 webpack 拾取。

最佳答案

我的错误在 package.json 中,我忘记删除了:

  "babel": {
    "presets": [
      "react-app"
    ]
  }

babel.config.js:

process.env.NODE_ENV = "development";

module.exports = {
    plugins: ["react-refresh/babel"],
    presets: [
        [
            "@babel/preset-typescript",
            {
                allExtensions: true,
                allowNamespaces: true,
                isTSX: true,
                optimizeConstEnums: true,
            },
        ],
        "@babel/preset-env",
        [
            "@babel/preset-react",
            {
                // https://babeljs.io/docs/en/babel-preset-react
                runtime: "automatic",
                pure: true,
                useBuiltIns: true,
            },
        ],
    ],
};

https://stackoverflow.com/questions/58747990/

相关文章:

c# - 如何检测进程是否移动了鼠标光标而不是用户?

go - 我可以防止 amqp.Channel 因错误而关闭吗?

reactjs - Material UI withStyles : Invalid prop `c

amazon-web-services - AWS DMS - 错误 - "AWS Account

javascript - 如何仅禁用 chrome 中的 "debugger"关键字,该关键字由循环

python - 如何在 Python 中移动文件?

flutter - 如何为 Flutter SliverList 中的元素设置动画?

angularjs - 一个指令内的多个方法返回

python-3.x - matplotlib 错误 : No module named matpl

python-3.x - 内置打印 (stdout) 的异步版本