将自定义的Modernizr构建添加到Gatsby站点

3

如何将自定义的Modernizr构建添加到Gatsby网站中?

一种思路是将modernizr.js文件包含在static/文件夹中,然后在布局组件中包含导入该文件的script标签。但这并不像是最适合Gatsby的方法。

如果有其他建议,那将非常有帮助!

2个回答

0

他们有一个npm包modernizr。也许可以试一下?

/src/pages/index.js中添加:

// Listen to a test, give it a callback
Modernizr.on('testname', function( result ) {
  if (result) {
    console.log('The test passed!');
  }
  else {
    console.log('The test failed!');
  }
});

0
将以下代码添加到您的 gatsby-ssr.js 文件中。
const React = require("react")
export const onRenderBody = ({ setHeadComponents }, pluginOptions) => {
  setHeadComponents([
    <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>,
  ])
}

这将加载 Modenizr 脚本并执行它


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接