iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >vite引入@vitejs/plugin-legacy解决在低版本安卓浏览器白屏问题
  • 322
分享到

vite引入@vitejs/plugin-legacy解决在低版本安卓浏览器白屏问题

前端 2023-09-05 08:09:12 322人浏览 泡泡鱼
摘要

使用es6语法可能在某些低版本安卓浏览器打开项目时白屏。 解决方案:引入@vitejs/plugin-legacy npm add -D @vitejs/plugin-legacy  --legacy-peer-deps 在vite.con

使用es6语法可能在某些低版本安卓浏览器打开项目时白屏。

解决方案:引入@vitejs/plugin-legacy

npm add -D @vitejs/plugin-legacy  --legacy-peer-deps

在vite.config.js配置文件中引入:
import legacy from '@vitejs/plugin-legacy'

配置:

plugins: [React(), eslintPlugin(), svgr({ exportAsDefault: true }),
    legacy({
      targets: ['defaults', 'ie >= 11', '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'
      ]
    })]

项目打包时出现这种情况:

 直接下载依赖即可:

npm i terser  --legacy--peer-deps

下载terser依赖失败,报错:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @vitejs/plugin-legacy@4.0.4
npm ERR! Found: vite@3.0.0
npm ERR! node_modules/vite
npm ERR!   peer vite@"^3.0.0" from @vitejs/plugin-react@2.2.0
npm ERR!   node_modules/@vitejs/plugin-react
npm ERR!     dev @vitejs/plugin-react@"^2.0.0" from the root project
npm ERR!   peer vite@">=2" from vite-plugin-eslint@1.7.0
npm ERR!   node_modules/vite-plugin-eslint
npm ERR!     dev vite-plugin-eslint@"1.7.0" from the root project
npm ERR!   2 more (vite-plugin-svgr, the root project)
npm ERR!
npm ERR! Could not resolve dependency:

可以考虑降低版本,如

npm add -D @vitejs/plugin-legacy@2.0.0  --legacy-peer-deps

来源地址:https://blog.csdn.net/weixin_53457368/article/details/131184944

--结束END--

本文标题: vite引入@vitejs/plugin-legacy解决在低版本安卓浏览器白屏问题

本文链接: https://www.lsjlt.com/news/394913.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作