我正在使用 Gatsby 构建前端,使用 WordPress 构建无头 CMS。当我对我的 WordPress 帖子进行更改时,我希望更改立即反映在我的 Gatsby 页面中。但是,当我进行更改时,我必须停止并重新启动服务器才能反映更改。我已查看 gatsby 文档并将“ENABLE_GATSBY_REFRESH_ENDPOINT”添加到我的环境文件中,但它不起作用。我做错了什么? 这是我的项目根目录下的 .env 中的内容
ENABLE_GATSBY_REFRESH_ENDPOINT=true
这是我的 gatsby-config 文件
import type { GatsbyConfig } from 'gatsby'
import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config()
const config: GatsbyConfig = {
siteMetadata: {
title: meta.title,
description: meta.description,
siteUrl: meta.siteUrl,
logo: meta.logo,
},
// More easily incorporate content into your pages through automatic TypeScript type generation and better GraphQL IntelliSense.
// If you use VSCode you can also use the GraphQL plugin
// Learn more at: https://gatsby.dev/graphql-typegen
graphqlTypegen: true,
plugins: [
'gatsby-plugin-postcss',
'gatsby-plugin-image',
'gatsby-plugin-sitemap',
{
resolve: 'gatsby-source-wordpress',
options: {
url:
// allows a fallback url if WPGRAPHQL_URL is not set in the env, this may be a local or remote WP instance.
`http://url/graphql`,
schema: {
//Prefixes all WP Types with "Wp" so "Post and allPost" become "WpPost and allWpPost".
typePrefix: `Wp`,
timeout: 3000000,
},
develop: {
//caches media files outside of Gatsby's default cache an thus allows them to persist through a cache reset.
hardCacheMediaFiles: true,
},
type: {
Post: {
limit:
process.env.NODE_ENV === `development`
? // Lets just pull 50 posts in development to make it easy on ourselves (aka. faster).
50
: // and we don't actually need more than 5000 in production for this particular site
5000,
},
Page: {
limit: 0,
},
MenuItem: {
limit: 0,
},
User: {
limit: 0,
},
Tag: {
limit: 0,
},
},
},
},
{
resolve: 'gatsby-plugin-manifest',
options: {
icon: 'src/images/logo.png',
},
},
'gatsby-plugin-sharp',
{
resolve: 'gatsby-plugin-sitemap',
options: {
exclude: ['/thankyou'],
},
},
'gatsby-transformer-sharp',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'images',
path: './src/images/',
},
__key: 'images',
},
'gatsby-plugin-react-svg',
{
resolve: 'gatsby-plugin-manifest',
options: {
name: meta.title,
short_name: meta.title,
start_url: '/',
background_color: 'white',
theme_color: '#101C45',
display: 'standalone',
lang: 'en',
icon: 'static/logo.png',
description: meta.description,
},
},
],
}
export default config