webpack5转化es6代码后,立即执行函数依旧是箭头函数

如图,里面的代码转化成es5了,但是最外层依旧是es6

 

 

我的babel配置

复制代码
 {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "babel-loader",
            options: {
              presets: [
                [
                  "@babel/preset-env",
                  {
                    targets: {
                      // chrome: "60",
                      // firefox: "60",
                      // safari: "10",
                      // edge: "17",
                      // ie: "8",
                      browsers: ["> 1%", "last 2 versions"],
                    },
                    corejs: 3,
                    useBuiltIns: "usage",
                  },
                ],
              ],
            },
          },
          "ts-loader",
        ],
      },
复制代码

解决方法:

1.将webpack将为版本4,版本5默认箭头函数输出

2.在配置文件webpack.config.json中的output内加上

 environment: {
      arrowFunction: false,//关闭箭头函数输出
    },

 environment其它配置

复制代码
module.exports = {
  output: {
    environment: {
      // The environment supports arrow functions ('() => { ... }').
      arrowFunction: true,
      // The environment supports BigInt as literal (123n).
      bigIntLiteral: false,
      // The environment supports const and let for variable declarations.
      const: true,
      // The environment supports destructuring ('{ a, b } = obj').
      destructuring: true,
      // The environment supports an async import() function to import EcmaScript modules.
      dynamicImport: false,
      // The environment supports 'for of' iteration ('for (const x of array) { ... }').
      forOf: true,
      // The environment supports ECMAScript Module syntax to import ECMAScript modules (import ... from '...').
      module: false,
    },
  },
};
复制代码

 

posted @   lijun12138  阅读(650)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示