通过 Webpack 5 应用程序构建后停止在 Internet Explorer (IE11) 上工作 [英] After build via Webpack 5 app stoped working on Internet Explorer (IE11)

查看:46
本文介绍了通过 Webpack 5 应用程序构建后停止在 Internet Explorer (IE11) 上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如在 Webpacks 5.0 发布博文中宣布的,在 webpack.config.js 中进行了一些小调整后,构建仍然适用于大多数浏览器.

As announced in Webpacks 5.0 release blog post build still works in most browsers after a few minor adjustments in webpack.config.js.

但它在 Internet Explorer (11) 中停止工作,因为生成的输出混合了 ES6ES5,因此与 IE 不兼容(见图).

But it stopped working in Internet Explorer (11) because the generated output is mixed ES6 and ES5 and therefore incompatible with IE (see image).

因为它实际上导致使用各种 babel 插件无法成功构建,所以我问自己是否有一个简单的"插件指定 ES5 作为生成输出的方法.

As it actually leads to no successful build using a variety of babel plugins I'm asking myself if theres an "easy" way to specify ES5 as the generated output.

webpack-5 的测试阶段开始,我在 Medium 似乎不再起作用了.

From beta phase of webpack-5 I found a flag on Medium which seems not working anymore.

module.exports = {
  output: {
    filename: [name].js,
    ecmaVersion: 5 // <- this flag
  }
}

版本 5.x 中是否有一些webpack 内置方式"将 ES5 作为输出目标?

Is there some "webpack built in way" in version 5.x to have ES5 as output target?

推荐答案

来自 webpack guide To v5 from v4,它说:

默认情况下,webpack 的运行时代码使用 ES2015 语法来构建更小的包.如果您的构建目标环境不支持此语法(如 IE11),则需要设置 target: ['web', 'es5'] 以恢复到 ES5 语法('web' 如果目标环境是浏览器).

By default, webpack's runtime code uses ES2015 syntax to build smaller bundles. If your build targets environments that don't support this syntax (like IE11), you'll need to set target: ['web', 'es5'] to revert to ES5 syntax ('web' if target environment is browser).

所以你可以尝试设置:

target: ['web', 'es5']

然后它将代码转换为 ES5.

then it will convert code to ES5.

这篇关于通过 Webpack 5 应用程序构建后停止在 Internet Explorer (IE11) 上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆