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, }, }, };
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通