-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-config.js
217 lines (195 loc) · 5.39 KB
/
gatsby-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
const { siteTitle } = require('./src/ui-texts');
const {
NODE_ENV,
NODE_VERSION,
PRODUCTION_SITE_URL,
COOKIEBOT_ID,
// Env vars set by Vercel
// See: https://vercel.com/docs/concepts/projects/environment-variables
GATSBY_VERCEL_ENV,
GATSBY_VERCEL_URL,
} = process.env;
const isVercel = !!GATSBY_VERCEL_ENV;
const VERCEL_URL = !/^https?:\/\//i.test(GATSBY_VERCEL_URL)
? 'https://' + GATSBY_VERCEL_URL
: GATSBY_VERCEL_URL;
/**
* Get the current env.
*
* Possible values:
*
* - 'local-development': local dev server
* - 'local-production': local prod server
* - 'vercel-production': production context in Vercel
* - 'vercel-preview': non-master branch preview deployment in Vercel
*/
const getEnv = () => {
if (isVercel) {
return `vercel-${GATSBY_VERCEL_ENV}`;
} else {
return `local-${NODE_ENV}`;
}
};
const getSiteUrl = env => {
if (env === 'local-development') {
return 'http://localhost:8000';
} else if (env === 'local-production') {
return 'http://localhost:9000';
} else if (env === 'vercel-production') {
return PRODUCTION_SITE_URL;
} else if (env === 'vercel-preview') {
return VERCEL_URL;
} else {
throw new Error(`Cannot construct siteUrl for unknown env: ${env}`);
}
};
// Dont prefix /docs in vercel deploy previews
const getPathPrefix = env => {
return (isVercel || env === 'local-production') && !(env === 'vercel-preview')
? '/docs'
: '';
};
const ENV = getEnv();
const SITE_URL = getSiteUrl(ENV);
const PATH_PREFIX = getPathPrefix(ENV);
console.log(PATH_PREFIX, 'path prefix');
console.log(ENV, 'env');
console.log({
NODE_ENV,
NODE_VERSION,
PRODUCTION_SITE_URL,
PATH_PREFIX,
ENV,
SITE_URL,
});
const withTrailingSlash = path => {
return path.endsWith('/') ? path : `${path}/`;
};
module.exports = {
trailingSlash: `always`,
// ================ Site metadata ================
//
siteMetadata: {
title: siteTitle,
siteUrl: SITE_URL,
},
plugins: [
// ================ Header metadata ================
//
'gatsby-plugin-react-helmet',
// ================ Markdown and images ================
//
'gatsby-transformer-sharp',
'gatsby-plugin-sharp',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'docs',
path: `${__dirname}/src/docs`,
},
},
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
{
resolve: 'gatsby-remark-images',
options: {
withWebp: { quality: 85 },
// Same as `contentMaxWidth` in the theme. The image
// won't be rendered any bigger.
maxWidth: 635,
quality: 85,
backgroundColor: 'transparent',
},
},
'gatsby-remark-copy-linked-files',
'gatsby-remark-autolink-headers',
{
resolve: 'gatsby-remark-prismjs',
options: {
noInlineHighlight: true,
},
},
{
resolve: 'gatsby-remark-external-links',
options: {
rel: 'noopener noreferrer',
},
},
],
},
},
'gatsby-plugin-catch-links',
// ================ Styles ================
//
'gatsby-plugin-styled-components',
// ================ Manifest ================
//
{
resolve: 'gatsby-plugin-manifest',
options: {
name: siteTitle,
short_name: 'Sharetribe Developer Platform',
start_url: '/',
background_color: '#f9f9f9',
theme_color: '#f9f9f9',
display: 'minimal-ui',
icon: 'src/images/logo.png', // This path is relative to the root of the site.
},
},
// ================ Sitemap ================
//
{
// NOTE: sitemap is NOT built with dev server
resolve: 'gatsby-plugin-sitemap',
options: {
excludes: [
'/styleguide',
'/thanks-for-the-feedback',
'/pilot-day-guides',
`/operator-guides`,
`/operator-guides/*`,
],
query: `
{
allSitePage {
nodes {
path
}
}
}
`,
resolveSiteUrl: () => SITE_URL,
resolvePages: ({ allSitePage: { nodes: allPages } }) => {
return allPages;
},
serialize: ({ path }) => {
return {
url: path,
// NOTE: These are optional and most likely ignored by Google et. al
//
// changefreq: 'daily',
// priority: 0.7,
};
},
},
},
],
};
// Cookiebot
// If you want to test cookiebot locally, add the cookiebotId directly here
if (isVercel) {
module.exports.plugins.push({
resolve: 'gatsby-plugin-cookiebot',
options: {
cookiebotId: COOKIEBOT_ID, // Required. Site's Cookiebot ID. Change this directly to the ID if on dev and you want to test cookiebot
blockGtm: false, // Optional. Skip blocking of GTM. Defaults to true if manualMode is set to true.
includeInDevelopment: true, // Optional. Enables plugin in development. Will cause gatsby-plugin-google-tagmanager to thrown an error when pushing to dataLayer. Defaults to false.
// pluginDebug: true, // Optional. Debug mode for plugin development. Defaults to false.
},
});
}
if (PATH_PREFIX) {
module.exports.pathPrefix = PATH_PREFIX;
}