模块构建使用Webpack4和Babel的反应应用程序失败

问题描述 投票:0回答:1

我的应用程序没有从我的反应应用程序中转换出JSX。

这是我的babel webpack配置:

module.exports = {
module: {
    rules: [
        {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader'
            }
        },

这是.babelrc的配置:

{
"plugins": [
    "@babel/plugin-transform-react-jsx-self",
    "transform-class-properties"
]

}

以下是我安装的dev依赖项:

"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-stage-2": "^7.0.0",
"babel-loader": "^8.0.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-react-jsx": "^6.24.1",

你可以看到我玩了几个不同的依赖,但我很确定问题在于我不明白如何在我的babelrc中正确配置它(这是我的第一次尝试)

其他答案我已阅读解决此问题使用webpack配置和babelrc中的babel预设,但babel最近在Babel7中弃用了这个

javascript reactjs webpack-4 babel-loader
1个回答
0
投票

所以如果有人有同样的问题。 babelrc的这个配置现在对我有用:

{
"presets": [
  ["@babel/env"],
  ["@babel/preset-react"]
],
"plugins": [
  ["transform-class-properties"],
  ["@babel/plugin-transform-react-jsx-self"]
]

}

© www.soinside.com 2019 - 2024. All rights reserved.