当前位置:网站首页>Vite2兼容低版本chrome(如搜狗80),通过polyfills处理部分需求高版本的语法
Vite2兼容低版本chrome(如搜狗80),通过polyfills处理部分需求高版本的语法
2022-06-30 20:23:00 【Program W】
初步处理
- 引入处理兼容问题的插件
npm install @vitejs/plugin-legacy -D
- 配置
vite.config.js targets:默认是package.json中的browserslist建议的值additionalLegacyPolyfillspolyfillsmodernPolyfills:启用此选项将为新式构建生成单独的polyfills块,官方不推荐使用,因为其自动检测的特性,配置后,即时浏览器支持,依然会使用nomodule进行加载polyfills的脚本(我这里是replaceAll()配置在polyfills,不生效,估计算前沿功能了,所以要么改写法,要么就得配在这里)
import legacy from '@vitejs/plugin-legacy'
plugins: [
vue(),
vueSetupExtend(),
AutoImport({
imports: ['vue', 'vue-router', 'vuex'],
}),
legacy({
// 尝试兼容低版本浏览器(不包括ie11)
targets: ['chrome 80'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'] //配置了对ie11也没用
})
]
配置后,会根据浏览器的支持动态加载不同的脚本,
<script nomodule>在不支持本机 ESM 的浏览器中有条件地加载polyfills和旧版捆绑包。
问题定位(语法问题)
vite打包后还是es6语法,有些语法要求版本比较高,需要通过polyfills(polyfills是通过在低版本浏览器中模拟等效的代码,来实现高版本语法的行为)进行处理
replaceAll ()支持的至少chrome85
TypeError: wye(...).replaceAll is not a function
兼容语法
polyfill无法直接使用,需要在plugin-legacy中使用,
legacy({
targets: ['chrome 80', 'ie >= 11'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // regenerator-runtime/runtime @dian/polyfill
renderLegacyChunks: true,
polyfills: [
'es.symbol',
'es.array.filter',
'es.promise',
'es.promise.finally',
'es/map',
'es/set',
'es.array.for-each',
'es.object.define-properties',
'es.object.define-property',
'es.object.get-own-property-descriptor',
'es.object.get-own-property-descriptors',
'es.object.keys',
'es.object.to-string',
'web.dom-collections.for-each',
'esnext.global-this',
'esnext.string.match-all',
// 这个无法处理
'es.string.replace-all'
]
})
- 换
modernPolyfills(成功处理)
legacy({
targets: ['chrome 80', 'ie >= 11'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // regenerator-runtime/runtime @dian/polyfill
renderLegacyChunks: true,
polyfills: [
'es.symbol',
'es.array.filter',
'es.promise',
'es.promise.finally',
'es/map',
'es/set',
'es.array.for-each',
'es.object.define-properties',
'es.object.define-property',
'es.object.get-own-property-descriptor',
'es.object.get-own-property-descriptors',
'es.object.keys',
'es.object.to-string',
'web.dom-collections.for-each',
'esnext.global-this',
'esnext.string.match-all'
],
modernPolyfills: ['es.string.replace-all']
})
modernPolyfills和polyfills的差异还不太清楚,慢慢再完善。。。
- 主流的
polyfills库为 core-js
边栏推荐
- 北京大学ACM Problems 1004:Financial Management
- B_QuRT_User_Guide(31)
- PM reports work like this, and the boss is willing to give you a raise
- 基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
- How do I get the largest K massive data
- NLP skill tree learning route - (I) route overview
- Peking University ACM problems 1003:hangover
- jfinal中如何使用过滤器监控Druid监听SQL执行?
- Basic concepts of tree
- MySQL:SQL概述及数据库系统介绍 | 黑马程序员
猜你喜欢
![翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]](/img/a8/6472e2051a295f5e42a88d64199517.png)
翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]

1. Introduction to generating countermeasures network

二叉查找树(一) - 概念与C语言实现

1、生成对抗网络入门

Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒

谈谈内联函数

基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享

Lumiprobe nucleic acid quantitative qudye dsDNA br detection kit
![Jerry's touch key recognition process [chapter]](/img/a4/3affa0f03db158ab68f69f935945e0.png)
Jerry's touch key recognition process [chapter]

基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
随机推荐
SQL优化
请指教在线开户需要什么银行卡?另外想问,现在在线开户安全么?
大神详解开源 BUFF 增益攻略丨直播
The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's first disciple
uniapp怎么上传二进制图片
Heartbeat uses NFS to make MySQL highly available based on CRM
Lumiprobe生物素亚磷酰胺(羟脯氨酸)说明书
Informatics Olympiad 1362: family problems
To eliminate bugs, developers must know several bug exploration and testing artifacts.
Notes on modification of Jerry's test box pairing software [chapter]
动态样式绑定--style 和 class
Lumiprobe cell biology - dia, instructions for lipophilic tracer
How do I get the largest K massive data
Scene 299
BioVendor sRAGE Elisa试剂盒测试原理和注意事项
Jenkins can't pull the latest jar package
MySQL简介、详细安装步骤及使用 | 黑马程序员
Installation and use of securecrtportable
Build your own website (20)
Jerry's touch key recognition process [chapter]

