在Gatsby配置文件中使用对象 [英] Using an Object in Gatsby Config File

查看:63
本文介绍了在Gatsby配置文件中使用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更好地组织我的gatsby配置文件,但是我不确定我做对了.有人知道以下设置是否可以工作:

I am trying to better organize my gatsby config file, but I"m not sure that I'm doing it right. Does anyone know if the following setup will work:

module.exports = {
  plugins: [
    { gatsby_plugin__manifest },
    { gatsby_source__file_system__images },
    { gatsby_source__file_system__posts },
  ],
};

const gatsby_plugin__manifest = {
  resolve: `gatsby-plugin-manifest`,
  options: {
    name: `gatsby-starter-default`,
    short_name: `starter`,
    start_url: `/`,
    background_color: `#663399`,
    theme_color: `#663399`,
    display: `minimal-ui`,
    icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
  },
}

const gatsby_source__file_system__images = {
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `images`,
    path: `${__dirname}/src/images`,
  },
}

const gatsby_source__file_system__posts = {
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `posts`,
    path: `${__dirname}/src/posts/`,
  },
}

我收到一条错误消息,说 gatsby_plugin__manifest不是定义,我想知道是否是因为我如何设置文件?

I got an error saying gatsby_plugin__manifest is not defined and I'm wondering if it is because of how I set up the file?

推荐答案

我在这里看到两个问题:

I see two issues here:

根据Gatbsy文档, plugins 是字符串或对象的数组.在ES6 {gatsby_plugin__manifest}中,是键值对 {gatsby_plugin__manifest:gatsby_plugin__manifest} 的简写.删除对象语法可以解决该问题.

According to the Gatbsy docs, plugins is an array of strings or objects. In ES6 { gatsby_plugin__manifest }, is shorthand for { gatsby_plugin__manifest: gatsby_plugin__manifest }, a key-value pair. Dropping the object syntax resolves that issue.

其次,出于

Second, declaring gatsby_plugin__manifest before it is referenced in the export causes a ReferenceError, for reasons described in this answer.

总结这些建议,仅针对其中一个插件:

To summarize these recommendations, for just one of the plugins:

// Declare gatsby_plugin__manifest before export
const gatsby_plugin__manifest = {
  resolve: `gatsby-plugin-manifest`,
  options: {
    // ...configuration here
  },
}

// Remove object syntax around gatsby_plugin__manifest
module.exports = {
  plugins: [
    gatsby_plugin__manifest,
  ],
};

Gatsby配置文档

这篇关于在Gatsby配置文件中使用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆