当前位置:网站首页>How vite is compatible with lower version browsers
How vite is compatible with lower version browsers
2022-07-02 05:50:00 【User experience officer Dalong】
One 、 problem
In the use of vue3.2 and vite2.0+ Develop a mobile terminal H5, During the test, it was found that many low version Android mobile browsers have white screens , and ios The model is basically good , as a result of Many lower version browsers do not support native ESM How to import , The solution is given below :
Two 、 Compatible with native ESM Browser
By default ,Vite The target browser of is able to Support native ESM script label and Support native ESM Dynamic import Of . As a reference ,Vite Use this browserslist As a query standard :
- Chrome >=87
- Firefox >=78
- Safari >=13
- Edge >=88
3、 ... and 、 Solution
Step one : vite.config.ts in build.target Configuration item Specify the build target as es2015
Step two : Through plug-ins @vitejs/plugin-legacy To automatically generate traditional browsers chunk And its corresponding ES Language characteristics polyfill. Compatible version chunk Only when native is not supported ESM Load on demand in your browser .
1、 install @vitejs/plugin-legacy
yarn add @vitejs/plugin-legacy -D2、 To configure vite.config.ts
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
legacy({
targets: ['chrome 52'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
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'
]
}
],
build: {
target: 'es2015'
}
})
Four 、 Packaging inspection
Check the packaged dist Inside index.html You know ,script There are two ways to introduce , Check that the current browser supports native ESM when , load <script type="module">, For lower version browsers, it will load <script nomodule> Corresponding js.

( End )
reference :
Build the production version | Vite Official Chinese documents ;
Remember a vite2.x Packaging optimization process - SegmentFault Think no
https://github.com/vitejs/vite/tree/main/packages/plugin-legacy
边栏推荐
- GRBL 软件:简单解释的基础知识
- I want to understand the swift code before I learn it. I understand it
- Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
- Reading notes of cgnf: conditional graph neural fields
- php获取cpu使用率、硬盘使用、内存使用
- all3dp.com网站中全部Arduino项目(2022.7.1)
- [technical notes-08]
- PHP read file (read the specified line containing a string in the file)
- RNN recurrent neural network
- LCD之MIPI协议的一些说明
猜你喜欢

Grbl software: basic knowledge of simple explanation

Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?

Vscode paste image plugin saves image path settings

How to write good code - Defensive Programming Guide

Lantern Festival gift - plant vs zombie game (realized by Matlab)

Software testing learning - day 4
![[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP](/img/25/73f11ab2711ed2cc9f20bc7f9116b6.png)
[whether PHP has soap extensions installed] a common problem for PHP to implement soap proxy: how to handle class' SoapClient 'not found in PHP

死磕大屏UI,FineReport开发日记

【論文翻譯】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond

Alibaba: open source and self-developed liquid cooling data center technology
随机推荐
PHP parent
Addchild() and addattribute() functions in PHP
Installation du tutoriel MySQL 8.0.22 par centos8
Opencv LBP features
Spark概述
XSS basic content learning (continuous update)
中小型项目手撸过滤器实现认证与授权
数据挖掘方向研究生常用网站
php内类名称与类内方法名相同
ThreadLocal memory leak
Software testing - concept
Reflection of the soul of the frame (important knowledge)
在线音乐播放器app
mysql的约束总结
Common protocols and download paths of NR
Practice C language advanced address book design
TypeScript的泛型和泛型约束
Basic use of form
File contains vulnerabilities (II)
Huawei Hongmeng OS, is it OK?