javascript - Webpack output two builds, one for ES6, one for IE11
问题描述
I have a webpack configuration of ES5/ES6 modules that works fairly well. Until recently it also ran through TargetsPlugin to generate a IE11-compatible build.
I say "until recently" because while experimenting, I noticed that dropping the babel transpiling to older language specs, we instantly shed 300KB from our bundles. If we turned this on, 90-point-something percent of our users would get a leaner, faster, better experience.
But I'm contractually obliged to support IE11. Can I do that separately?
What I want is a ES6-ish build (what we have) and a companion IE11 build. It's not difficult to target these browsers programmatically when it comes to switching out what version they see... But how do I get webpack to do it?
If it makes any difference, I don't need the IE11 version to have any fancy features. It can be one 1MB amorphous blob, or fully chunked out. However it comes, as long as it works.
解决方案
好的,事实证明 webpack 可以同时处理多个配置。在通常情况下module.exports = { ... config ... }
,您实际上可以返回一个配置对象数组。
所以我做了这样的事情:
var realConfig = {
...
}
var ie11 = _.cloneDeep(real)
ie11.output.filename = 'js/ie11.[name].js'
ie11.plugins.push(
new TargetsPlugin({ browsers: ["IE >= 11"] })
)
module.exports = [ realConfig, ie11 ]
这给了我所有东西的 IE 兼容版本。在我的模板中,我只是在用户代理中检测到“MSIE”并将其输出。可能不是最可靠的,但构建也应该适用于现代浏览器,所以我不担心。
推荐阅读
- c - 如何打印 2 个给定整数之间的平方整数数?[C程序]
- flutter - 如何在颤动中清除 PaginatedDataTable 的 DataTableSource?
- python - 如果我有身体部位坐标,如何叠加两张不同大小和纵横比的人的图像?
- installation - 点安装 https://github.com/tijme/angularjs-csti-scanner/archive/master.zip
- azure-synapse - Azure 数据仓库中的“Cursor”和“FOR XML”子句
- javascript - 从反应应用程序(端口 3000)发布到节点服务器(端口 8080)时出现 404 错误
- python - Google OR-Tools NotImplementedError:不支持将 BoundedLinearExpr 评估为布尔值
- arduino - 如何使用与 arduino nano 相同的代码到 Seeeduino xiao?
- c# - Xamarin Forms:如何使动态创建的项目可点击?
- java - SimpleDateFormat 以“S”格式显示不正确的毫秒数,但“SSS”则不显示