javascript - 删除浏览器支持并使用 webpack 显示 html 页面
问题描述
我试图弄清楚如何放弃浏览器支持。例如 IE11,如何使用 webpack 执行此操作并防止它捆绑代码,因为它无论如何都会中断。并显示该浏览器的 UI(不支持浏览器...)。我遇到了浏览器列表,我知道它是用于浏览器选择的,但找不到使用它的解决方法。
假设我有一些实用功能 isIE11 可以检测浏览器,并且想做这样的事情:
{
entry: isIE11 ? 'index.ie11.js' : 'index.js',
output: {
path: __dirname + '/dist',
filename: 'index_bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
title: 'My App',
template: isIE11 ? 'src/ie11.index.html.hbs' : 'src/index.html.hbs'
filename: 'assets/index.html'
})
]
}
即使在 ie11 中显示这个简单的 UI 时也不需要模块
解决方案
该插件将在您编译时运行......所以那时没有浏览器。
您可以做的一件事可能是在没有 ie11 支持的情况下编译它(在 babel 配置中?)...然后在 html 页面中,将一个单独的脚本放在顶部的脚本标记中,以检查不受支持的浏览器,然后重定向你,或者只是用消息替换当前页面:
<script>
if (... code to check browser) {
window.location = "ie11.index.html";
}
// and then you have to deploy the ie11 index page
</script>
或者如果是短消息
<script>
if (... code to check browser) {
document.getObjectById('main-div').innerHTML = 'Welcome to the ie version';
} else {
// do what you normally do - put the real content into `main-div`
}
</script>
推荐阅读
- python - Python Pandas - 新的列分组和模式
- javascript - 在没有“记住我”复选框的情况下让我永远登录
- javascript - 在javascript中查找链接
- javascript - 设置变量“onsubmit”以供以后使用
- angular - 试图从数据库中获取数据。角 6
- r - dplyr 使用 ifelse 过滤数据框变量的值?
- swift - NSSelectorFromString 和 Selector 结构
- regex - 如何构建以 [az][AZ] 开头并以数字结尾的正则表达式
- python - 如何解决“pyspark”无法识别... Windows 上的错误?
- pandas - 合并两个数据框时复制行