当前位置:网站首页>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
边栏推荐
- 翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]
- 大神詳解開源 BUFF 增益攻略丨直播
- Binary search tree (1) - concept and C language implementation
- Peking University ACM problems 1001:exposition
- 注册设备监理师难考吗,和监理工程师有什么关系?
- 数据库 OLAP、OLTP是什么?相同和不同?适用场景
- Label Contrastive Coding based Graph Neural Network for Graph Classification
- NLP skill tree learning route - (I) route overview
- Comparison between QT and other GUI Libraries
- 左值引用和右值引用
猜你喜欢

A complete collection of vulnerability scanning tools. Mom doesn't have to worry that I won't find any more vulnerabilities

Basic concepts of tree

Lumiprobe无铜点击化学解决方案

Build your own website (20)

Huffman Tree (1) Basic Concept and C - language Implementation
![[1175. prime number arrangement]](/img/f2/d427db03da151786ea1dfb7a76328a.png)
[1175. prime number arrangement]

为什么vscode用久了电脑速度变慢?

PHP require/include differences

Jenkins can't pull the latest jar package
![Jerry's touch key recognition process [chapter]](/img/3e/bb73c735d0a7c7a26989c65a432dad.png)
Jerry's touch key recognition process [chapter]
随机推荐
Web host iptables firewall security script
obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
Playwright - scroll bar operation
好高的佣金,《新程序员》合伙人计划来袭,人人皆可参与
Wechat applet development practice cloud music
Document contains & conditional competition
1. Introduction to generating countermeasures network
Jerry's determination of detection sensitivity level [chapter]
Maya House Modeling
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
数据库 OLAP、OLTP是什么?相同和不同?适用场景
Great God detailed open source Buff gain Introduction 丨 Live
Jerry's touch key recognition process [chapter]
Description of the latest RTSP address rules for Hikvision camera, NVR, streaming media server, playback and streaming [easy to understand]
数据库 OLAP、OLTP是什么?相同和不同?适用场景
北京大学ACM Problems 1003:Hangover
Game 81 biweekly
Informatics Olympiad 1362: family problems
股票开户优惠链接,我如何才能得到?另外,手机开户安全么?

