【问题标题】:Polyfilling Set in Gatsby盖茨比中的 Polyfilling 集
【发布时间】:2019-07-06 20:06:32
【问题描述】:

我正在使用默认的 polyfill 选项,尽管 Gatsby 没有在我的网站上为 iPhone 5 /5S 和其他一些较旧的浏览器正确地进行 polyfill(尽管在 IE11 上似乎可以工作)。

ReferenceError: Can't find variable: Set

不确定我应该在哪里设置 polyfill 或为什么 Gatsby 没有在所有设备上正确设置。

我尝试了gatsby-plugin-polyfill-io 插件,这似乎使事情变得更糟,而是创建了错误Uncaught TypeError: Cannot read property 'split' of undefined

有什么想法或建议吗?

【问题讨论】:

    标签: javascript gatsby polyfills


    【解决方案1】:

    你应该在 gatsby-browser.js 上添加 polyfill 例如:

    export const onClientEntry = async () => {
      if (typeof IntersectionObserver === 'undefined') {
        await import('intersection-observer');
        console.log('? intersection-observer imported')
      }
    } 
    

    或者 gatsby-ssr.js

    export const onRenderBody =({ setPostBodyComponents }, options) =>{
        setPostBodyComponents([
            <script
                src="https://cdn.polyfill.io/v3/polyfill.min.js"
            />
        ])
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-16
      • 2019-08-07
      • 2021-12-14
      • 2022-08-19
      • 2019-04-02
      • 2021-07-30
      • 1970-01-01
      • 2020-12-02
      相关资源
      最近更新 更多