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

标签 gatsby modernizr

将自定义 Modernizr 构建添加到 Gatsby 站点的最佳方法是什么?

一种想法是在 static/ 文件夹中包含一个 modernizr.js 文件,然后在布局组件中包含一个导入该文件的脚本标签。但这并不是对 Gatsby 最友好的方法。

任何其他建议都会非常有帮助!

最佳答案

他们有一个 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!');
  }
});

关于gatsby - 将自定义 Modernizr 构建添加到 Gatsby 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55591828/

相关文章:

reactjs - Gatsby 404 Page 正在提示 Google map

javascript - Gatsby :为什么我(或者我什至?)需要使用exports.onCreateNode 来创建页面?

javascript - 使用 modernizr 确定是否支持多窗口打开

javascript - yepnope.js 在已加载的脚本之上注入(inject)脚本

jquery - 在 Gatsby 中使用 jQuery 和外部脚本

seo - 带有react-helmet和gatsby的动态元标签不起作用

reactjs - 如何在 gatsby Contentful Rich Text 中有选择地查询引用?

requirejs - 我应该在同一页面中使用 Modernizrjs + YepNopejs + Requirejs 吗?

javascript - 为什么 modernizr 不附加我的 html 类?

css - Modernizr 和后代选择器?