【发布时间】:2021-05-21 07:21:05
【问题描述】:
我在 Gatsby@2.2.10 建立了一个网站。当我运行 gatsby build 并检查生成的 html 时,对于每个页面,我看到的只是一个空 div:<div id="___gatsby"></div。 html 包含样式表、javascript 文件和运行应用程序所需的一切(顺便说一句)。
即使我curl生产的url,同样的div出现并且完全是空的。我还尝试禁用 javascript,但我得到的只是一个空白页。我的配置没有什么花哨的:
module.exports = {
siteMetadata: {
title : `MyApp`,
description: ``,
author : ``,
},
plugins : [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/static/images`,
},
},
{
resolve: `gatsby-plugin-less`,
options: {
javascriptEnabled: true,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sass`,
`gatsby-plugin-sharp`,
`gatsby-plugin-typescript`,
`gatsby-plugin-styled-components`,
{
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [
`Montserrat\:200,400,600,800`,
],
},
},
{
resolve: `gatsby-plugin-manifest`,
options: {
name : `MyApp.com`,
short_name : `MyApp`,
start_url : `/`,
background_color: `#4DECDB`,
theme_color : `#2F57E4`,
display : `minimal-ui`,
icon : `src/static/images/logo.png`,
},
},
`gatsby-plugin-offline`,
{
resolve: `gatsby-plugin-google-analytics`,
options: {
// replace "UA-XXXXXXXXX-X" with your own Tracking ID
trackingId: 'UA-111111111-16',
},
},
// last
'gatsby-plugin-netlify',
],
}
我的gatbsy-node 文件是空的,gatsby-browser 只加载了一个样式表和一个 redux 存储:
import wrapWithProvider from './wrap-wit-provider'
import './src/components/layout/styles.less'
export const wrapRootElement = wrapWithProvider
我应该寻找什么想法?除非由于不存在的 html 代码,Netlify 无法检测到我的表单并处理它们,否则我不会那么担心。
【问题讨论】:
-
我相信看到空的
<div id="___gatsby"></div>很好。 React 应用程序是动态生成的,并且不存在于静态布局中。那么,您要解决的问题是什么? -
Gatsby 是一个静态站点生成器。它应该为搜索引擎输出静态内容。您可以在另一个 Gatby 支持的网站上进行测试:
curl https://www.qards.io/a-blog-that-is-100-free-can-serve-any-traffic-and-is-unhackable/ | grep "fully functional website" -
您是否尝试按照这些步骤操作? gatsbyjs.org/docs/debugging-html-builds 真的很难说问题出在哪里。
-
你能检查我的答案吗?如果它没有帮助,那么请详细说明这个问题。
-
我会说它是
wrapWithProvider函数。你能分享一下它的样子吗?它包装了根元素,因此您必须返回一个组件,其中包含调用它的参数
标签: javascript gatsby