This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
gatsby-config.js
305 lines (287 loc) · 8.14 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// NOTE:
// This file could've been converted to TS,
// but the only way to get rehype-slug to play nice was
// to keep it as a commonJS module. Otherwise
// rehype-slug would cause gatsby to throw errors
// when building pages.
// rehype-slug is used to generate id's for headings, which
// we link to from the table of contents on a page.
const path = require('path')
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`,
})
const { queries } = require('./src/utils/algolia')
const isStaging = process.env.GATSBY_ACTIVE_ENV === 'staging'
const isProd = process.env.GATSBY_ACTIVE_ENV === 'production'
const buildDevIndex = !!process.env.BUILD_DEV_ALGOLIA_INDEX
// These are useful to debug build issues
console.log(`
GATSBY_ACTIVE_ENV=${process.env.GATSBY_ACTIVE_ENV}
GATSBY_BUCKET_PREFIX=${process.env.GATSBY_BUCKET_PREFIX}
GATSBY_ALGOLIA_INDEX=${process.env.GATSBY_ALGOLIA_INDEX}
GATSBY_ALGOLIA_APP_ID=${process.env.GATSBY_ALGOLIA_APP_ID}
`)
if (isStaging && !process.env.GATSBY_BUCKET_PREFIX) {
throw new Error("There's no GATSBY_BUCKET_PREFIX to deploy to staging")
}
const wrapESMPlugin = name =>
function wrapESM(opts) {
return async (...args) => {
const mod = await import(name)
const plugin = mod.default(opts)
return plugin(...args)
}
}
const loadImagesAndTopics = () => {
// Omit mdx images in fast dev mode
if (process.env.DEV_FAST !== 'true') {
return [
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'mdx-images',
path: `${__dirname}/src/content/images`,
fastHash: true,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/content/topics`,
name: 'mdx',
fastHash: true,
},
},
]
}
return [
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/content/topics/`,
name: 'mdx',
fastHash: true,
// Omit all mdx but getting-started, managing-flags, managing-users in fast dev mode
ignore: [
'**/guides',
'**/integrations',
'**/sdk',
'**/home/account-security',
'**/home/advanced',
'**/home/about-experimentation',
'**/home/billing',
],
},
},
]
}
const plugins = [
{
resolve: 'gatsby-plugin-root-import',
options: {
'@': path.join(__dirname, 'src'),
},
},
{
resolve: 'gatsby-plugin-mdx',
options: {
extensions: ['.mdx', '.md'],
mdxOptions: {
rehypePlugins: [wrapESMPlugin('rehype-slug')],
},
gatsbyRemarkPlugins: [
{
resolve: 'gatsby-remark-relative-images-v2',
},
{
resolve: 'gatsby-remark-images',
options: {
maxWidth: 640,
showCaptions: true,
// solution based loosely on https://github.com/gatsbyjs/gatsby/issues/15241#issuecomment-1022846561
wrapperStyle(image) {
let maxImageWidth
let maxImageHeight
// force the max in either direction to be 640, then scale
if (image.aspectRatio < 1) {
maxImageWidth = image.aspectRatio * 640
maxImageHeight = 640
} else {
maxImageWidth = 640
maxImageHeight = image.aspectRatio * 640
}
return `max-width: ${maxImageWidth}px; max-height: ${maxImageHeight}px; margin-left: auto; margin-right: auto;`
},
},
},
'gatsby-remark-copy-linked-files',
],
},
},
...loadImagesAndTopics(),
'gatsby-plugin-theme-ui',
'gatsby-transformer-json',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'navigationData',
path: `${__dirname}/src/content/navigationData.json`,
fastHash: true,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'rootTopics',
path: `${__dirname}/autoGeneratedData/rootTopics.json`,
fastHash: true,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'secondLevelTopics',
path: `${__dirname}/autoGeneratedData/secondLevelTopics.json`,
fastHash: true,
},
},
{
resolve: 'gatsby-plugin-svgr-loader',
options: {
rule: {
options: {
svgoConfig: {
plugins: [
{ name: 'removeAttrs', params: { attrs: ['fill', 'path:fill'] } },
{
name: 'removeViewBox',
active: false,
},
{
name: 'removeDimensions',
active: true,
},
],
},
},
include: /icons/,
},
},
},
'gatsby-transformer-sharp',
'gatsby-plugin-sharp',
'gatsby-plugin-catch-links',
{
resolve: 'gatsby-plugin-manifest',
options: {
name: 'LaunchDarkly Docs',
short_name: 'LD Docs',
start_url: '/',
background_color: '#0E1932',
theme_color: '#FFF',
display: 'minimal-ui',
icon: 'assets/icons/favicon-osmo-prod.svg', // This path is relative to the root of the site.
},
},
{
resolve: 'gatsby-plugin-google-gtag',
options: {
trackingIds: ['G-P12DWV2SBZ', 'G-31EH4XPW51'],
pluginConfig: {
head: true,
},
},
},
{
resolve: 'gatsby-plugin-google-tagmanager',
options: {
id: 'GTM-M4F7FSC',
},
},
{
resolve: 'gatsby-plugin-launchdarkly',
options: {
clientSideID: process.env.LAUNCHDARKLY_CLIENT_SIDE_ID,
options: {
baseUrl: 'https://sdk.ld.catamorphic.com',
streamUrl: 'https://stream.ld.catamorphic.com',
eventsUrl: 'https://events.ld.catamorphic.com',
bootstrap: 'localStorage',
},
},
},
]
if (isStaging || isProd || buildDevIndex) {
plugins.push({
// Only build algolia indexes in staging and production, or if a special
// env var is set
resolve: 'gatsby-plugin-algolia',
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_KEY,
queries,
chunkSize: 10000, // default: 1000
continueOnFailure: false,
enablePartialUpdates: true,
},
})
}
if (isStaging || isProd) {
plugins.push({
resolve: 'gatsby-plugin-s3',
options: {
bucketName: process.env.AWS_S3_BUCKET,
bucketPrefix: process.env.GATSBY_BUCKET_PREFIX,
protocol: 'https',
hostname: process.env.AWS_HOSTNAME,
generateRedirectObjectsForPermanentRedirects: true,
generateIndexPageForRedirect: isProd, // this is on by default, but should should be off in staging
enableS3StaticWebsiteHosting: false,
},
})
}
const { SEGMENT_KEY } = process.env
if (SEGMENT_KEY) {
plugins.push({
//https://www.gatsbyjs.org/packages/gatsby-plugin-segment-js/
resolve: 'gatsby-plugin-segment-js',
options: {
prodKey: SEGMENT_KEY,
devKey: SEGMENT_KEY,
//track pageviews when there is a route change. Calls window.analytics.page() on each route change.
trackPage: true,
delayLoad: false,
},
})
}
if (isProd) {
plugins.push({
resolve: 'gatsby-plugin-sitemap',
options: {
excludes: ['/systemLayout/', '/components'],
},
})
}
if (!isProd) {
// GOTCHA: On dev and staging, the client side redirect plugin auto-generates index.html files
// which acts as default pages which contains scripts to enforce redirects defined in
// gatsby-node.js. Production doesn't need this because gatsby-plugin-s3 does this for us
// automatically
// Re:staging - the s3 plugin doesn't properly generate redirects when using bucketPrefix
// Track issue here: https://github.com/jariz/gatsby-plugin-s3/issues/24
plugins.push('gatsby-plugin-client-side-redirect')
}
const config = {
pathPrefix: isStaging ? `/${process.env.GATSBY_BUCKET_PREFIX}` : '/',
siteMetadata: {
title: 'LaunchDarkly Docs',
description: 'LaunchDarkly documentation',
author: '@launchdarkly',
siteUrl: 'https://docs.launchdarkly.com',
},
plugins,
trailingSlash: 'never',
jsxRuntime: 'automatic',
jsxImportSource: 'theme-ui',
}
module.exports = config