我在和盖茨比的资料来源wordpress合作
plugin
如果我硬编码我的API key/secret到Gatsby.config中,一切正常,但我想将它们添加为.env变量,这样我就可以.gitignore进行部署,这就是问题所在。
在目录的根目录中,我有一个.env文件,它如下所示
CLIENT_SECRET=10987654321
CLIENT_ID=123456
USER=secret@secret.com
PASS=mypassword1
然后我尝试在gatsby.config中访问这些,如下所示
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`
});
module.exports = {
siteMetadata: {
title: 'Gatsby Default Starter',
},
plugins: [
{
resolve: 'gatsby-source-wordpress',
options: {
baseUrl: 'myurl.com',
protocol: 'http',
hostingWPCOM: true,
useACF: false,
auth: {
wpcom_app_clientSecret: `${process.env.CLIENT_SECRET}`,
wpcom_app_clientId: `${process.env.CLIENT_ID}`,
wpcom_user: `${process.env.USER}`,
wpcom_pass: `${process.env.PASS}`,
},
},
},
{
resolve: `gatsby-plugin-emotion`,
},
'gatsby-plugin-react-helmet',
{
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.
},
},
'gatsby-plugin-offline',
],
}
当我运行gatsby develop或gatsby build时返回以下错误
所以,问题是.env变量似乎没有正确地通过,但我看不出它们不通过的原因?我在设置这个过程中遗漏了什么吗?