V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hu1e
V2EX  ›  程序员

vitejs/plugin-legacy 这个插件是怎么做到兼容 chorme < 60, firefox < 59 的?

  •  
  •   hu1e · 37 天前 · 792 次点击
    这是一个创建于 37 天前的主题,其中的信息可能已经有所发展或是发生改变。
    // legacy 可以支持通过配置下列配置去兼容传统浏览器
    legacy({
        targets: ['chrome < 60', 'edge < 15', 'firefox <= 52'],
    })
    

    据我所知,plugin-legacy 是通过利用 script nomodule 去加入兼容性代码,但是 script nomodule 不支持 chrome < 60 、firefox < 59 ,所以这是怎么办到的?直接判断版本强行插入普通 script 去执行兼容性代码么?

    2 条回复    2024-03-22 16:43:43 +08:00
    codehz
        1
    codehz  
       36 天前   ❤️ 1
    nomodule 的兼容性是指:支持 nomodule 的浏览器就不去加载这个 script
    不支持 nomodule 的就会自动加载(因为不认识的 attribute 被忽略)
    hu1e
        2
    hu1e  
    OP
       36 天前
    @codehz 原来是这样,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5376 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 08:41 · PVG 16:41 · LAX 01:41 · JFK 04:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.