我正在使用 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/