当前位置:网站首页>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
边栏推荐
- 左值引用和右值引用
- 股票开户优惠链接,我如何才能得到?另外,手机开户安全么?
- 为什么vscode用久了电脑速度变慢?
- Lumiprobe cell biology - dia, instructions for lipophilic tracer
- What bank card do you need to open an account online? In addition, is it safe to open an account online now?
- How can I get the stock account opening discount link? In addition, is it safe to open a mobile account?
- unittest自动测试多个用例时,logging模块重复打印解决
- Lumiprobe biotin phosphimide (hydroxyproline) instructions
- To eliminate bugs, developers must know several bug exploration and testing artifacts.
- Testing principle and precautions of biovendor rage ELISA Kit
猜你喜欢

浅谈代码语言的魅力
![Halcon knowledge: check the measurement objects [1]](/img/0a/3a12e281fcb201d8d11b25dac4145a.png)
Halcon knowledge: check the measurement objects [1]

偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的

Lumiprobe核酸定量丨QuDye dsDNA BR 检测试剂盒

DEX文件解析 - method_ids解析

MySQL:SQL概述及数据库系统介绍 | 黑马程序员

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

1、生成对抗网络入门

Implementation principle of PostgreSQL heap table storage engine

Testing principle and precautions of biovendor rage ELISA Kit
随机推荐
Lvalue reference and lvalue reference
Is it safe to open an account for online stock trading!?
北京大学ACM Problems 1000:A+B Problem
Playwright - scroll bar operation
On inline function
DEX file parsing - Method_ IDS resolution
Peking University ACM problems 1001:exposition
Jerry's determination of detection sensitivity level [chapter]
Lumiprobe染料酰肼丨BDP FL 酰肼方案
哈夫曼樹(一)基本概念與C語言實現
Maya house modeling
Informatics Olympiad 1362: family problems
基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
Basic concepts of tree
How do I get the largest K massive data
PM reports work like this, and the boss is willing to give you a raise
我想知道股票开户要认识谁?另外,手机开户安全么?
断点续传和下载原理分析
Jerry's touch key recognition process [chapter]
1、生成对抗网络入门

