简体   繁体   English

webpack 忽略.babelrc 和 babel.config.js

[英]webpack ignores .babelrc and babel.config.js

I am using webpack 4.32.2, and @babel/core 7.2.0我正在使用 webpack 4.32.2 和 @babel/core 7.2.0

my webpack config is located here我的 webpack 配置位于此处

projectroot/build/webpack.config.js

When I run my webpack config everything works fine except that my babel.config.js, which is located here当我运行我的 webpack 配置时,一切正常,除了我的 babel.config.js,它位于这里

projectroot/babel.config.js

is simply being ignored.只是被忽略了。

It's the same if I use如果我使用它是一样的

projectroot/.babelrc

None of these files seems to matter.这些文件似乎都不重要。

Here's what the babel loader section in webpack.config.js looks like (note I've added the rootMode: 'upward' directive to make sure that any.babelrc or babel.config.js in any above directory is being found:这是 webpack.config.js 中的 babel loader 部分的样子(注意我添加了 rootMode: 'upward' 指令以确保在上述任何目录中都可以找到 any.babelrc 或 babel.config.js:

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

I'd like to be able to use babel.config.js but if there's a problem with that I'd also go with.babelrc.我希望能够使用 babel.config.js,但如果有问题,我也会使用 go 和.babelrc。 At the moment neither one is being picked up by webpack.目前,webpack 都没有接听任何一个。

My error was in package.json, i forgot to delete:我的错误出现在 package.json 中,我忘了删除:

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

babel.config.js: 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,
            },
        ],
    ],
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM