gpt4 book ai didi

webpack + babel - 转换对象箭头功能不起作用

转载 作者:行者123 更新时间:2023-12-03 18:25:03 25 4
gpt4 key购买 nike

我正在尝试使用 babel 配置 webpack (5),使用 babel-loader 转译为 ES5。
不幸的是,输出不一致。基本上,它分为两部分:

  • 一些 polyfill:

  • 我的代码:


  • 如您所见,第一部分包含箭头函数,第二部分没有。
    我尝试添加 @babel/plugin-proposal-class-properties@babel/plugin-transform-arrow-functions到我的 .babelrc文件,但 class-properties丢失(启用调试)。
    我必须承认,我不确定 class-properties是问题所在,但在谷歌上花了几个小时后,这是我最好的尝试,所以也许我对问题根源的看法是错误的。
    网络包文件:
    export default {
    entry: './src/index.js',
    mode: 'production',
    output: {
    path: path.resolve(__dirname, '..', '..', 'dist'),
    filename: 'bundle.prod.js'
    },
    module: {
    rules: [
    {
    test: /\.m?js$/,
    exclude: /node_modules/,
    use: {
    loader: 'babel-loader'
    }
    }
    ]
    }
    }
    .babelrc文件:
    {
    "presets": [
    [
    "@babel/preset-env",
    {
    "corejs": {
    "version": 3
    },
    "useBuiltIns": "usage",
    "debug": true
    }
    ]
    ],
    "plugins": [
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-transform-arrow-functions"
    ]
    }
    节点依赖:
    "@babel/core": "7.11.6",
    "@babel/plugin-proposal-class-properties": "7.10.4",
    "@babel/plugin-transform-arrow-functions": "7.10.4",
    "@babel/preset-env": "7.11.5",
    "@babel/register": "7.11.5",
    "babel-loader": "8.1.0",
    "core-js": "3.6.5",
    "webpack": "5.0.0",
    "webpack-cli": "4.0.0",
    "webpack-merge": "5.2.0"

    最佳答案

    我在 webpack v5 上遇到了类似的问题
    Arrow Function in Bootstrap
    我需要从 webback 更改配置并添加:
    目标:['es5']

            module: {
    rules: [.....]
    },
    resolve: {
    extensions: [".ts", ".tsx", ".js"]
    },
    target: ['es5']
    Weback V5 target config

    关于webpack + babel - 转换对象箭头功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64339314/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com