Vite是如何兼容旧版本浏览器的

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + Vue + TS</title>
    <script type="module" crossorigin src="/assets/index-7bacbbdc.js"></script>
    <link rel="stylesheet" href="/assets/index-ea6784f3.css" />
    
    <script type="module">
      import.meta.url;
      import('_').catch(() => 1);
      async function* g() {}
      if (location.protocol != 'file:') {
        window.__vite_is_modern_browser = true;
      }
    </script>
    
    <script type="module">
      !(function () {
        if (window.__vite_is_modern_browser) return;
        console.warn('vite: loading legacy chunks, syntax error above and the same error below should be ignored');
        var e = document.getElementById('vite-legacy-polyfill'),
          n = document.createElement('script');
        (n.src = e.src),
          (n.onload = function () {
            System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'));
          }),
          document.body.appendChild(n);
      })();
    </script>
    
  </head>
  <body>
    <div id="app"></div>

    <script nomodule crossorigin id="vite-legacy-polyfill" src="/assets/polyfills-legacy-3189795e.js"></script>
    
    <script nomodule crossorigin id="vite-legacy-entry" data-src="/assets/index-legacy-151e35d2.js">
      System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'));
    </script>
  </body>
</html>

在这里插入图片描述
在这里插入图片描述

<script type="module">
  !(function () {
    if (window.__vite_is_modern_browser) return;
    console.warn('vite: loading legacy chunks, syntax error above and the same error below should be ignored');
    var e = document.getElementById('vite-legacy-polyfill'),
      n = document.createElement('script');
    (n.src = e.src),
      (n.onload = function () {
        System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'));
      }),
      document.body.appendChild(n);
  })();
</script>

在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- 代码执行,加载index文件 -->
    <script type="module" crossorigin src="/assets/index-7bacbbdc.js"></script>
    <!-- 代码执行,报错,__vite_is_modern_browser为undefined -->
    <script type="module">
      import.meta.url;
      import('_').catch(() => 1);
      async function* g() {}
      if (location.protocol != 'file:') {
        window.__vite_is_modern_browser = true;
      }
    </script>

    <!-- 代码执行,加载兼容的polyfills-legacy文件 和 index-legacy文件 -->
    <script type="module">
      !(function () {
        if (window.__vite_is_modern_browser) return;
        console.warn('vite: loading legacy chunks, syntax error above and the same error below should be ignored');
        var e = document.getElementById('vite-legacy-polyfill'),
          n = document.createElement('script');
        (n.src = e.src),
          (n.onload = function () {
            System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'));
          }),
          document.body.appendChild(n);
      })();
    </script>
  </head>
  <body>
    <div id="app"></div>
    <!-- 不执行 -->
    <script nomodule crossorigin id="vite-legacy-polyfill" src="/assets/polyfills-legacy-3189795e.js"></script>
    <!-- 不执行 -->
    <script nomodule crossorigin id="vite-legacy-entry" data-src="/assets/index-legacy-151e35d2.js">
      System.import(document.getElementById('vite-legacy-entry').getAttribute('data-src'));
    </script>
  </body>
</html>

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue 3是一种流行的JavaScript框架,它提供了一种简洁、高效的方式来构建用户界面。Vite是一个基于ES模块的构建工具,它专注于快速的开发体验。而TypeScript是一种静态类型检查的JavaScript超集,它可以增强代码的可读性和可维护性。 在浏览器兼容性方面,Vue 3、Vite和TypeScript都有一些要注意的事项: 1. Vue 3:Vue 3相对于Vue 2有一些重要的变化,其中一个是使用了ES模块作为默认的模块系统。这意味着在一些旧版本浏览器中可能不被支持。为了解决这个问题,你可以使用Babel等工具进行转译,以确保Vue 3代码在目标浏览器中能够正常运行。 2. ViteVite使用ES模块作为默认的模块系统,并且利用现代浏览器的原生ES模块支持来提供快速的开发体验。然而,对于一些旧版本浏览器,可能需要进行转译和polyfill处理。你可以使用Babel和相关插件来处理这些兼容性问题。 3. TypeScript:TypeScript可以编译为普通的JavaScript代码,并且可以在大多数现代浏览器中运行。然而,一些较旧的浏览器可能不支持所有的ES6+特性,因此你可能需要使用Babel等工具来进行转译和polyfill处理。 总结起来,为了在Vue 3、Vite和TypeScript项目中实现浏览器兼容性,你可以采取以下步骤: 1. 使用Babel:配置Babel来转译和处理目标浏览器不支持的特性。 2. 使用Polyfill:使用Polyfill来填充目标浏览器缺少的功能。 3. 针对不同浏览器版本进行测试:确保你的应用在目标浏览器中能够正常运行,并进行必要的调整和修复。 4. 参考官方文档:查阅Vue 3、Vite和TypeScript的官方文档,了解更多关于浏览器兼容性的建议和最佳实践。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JackieChan_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值