forked from launchdarkly/LaunchDarkly-Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-config.js
234 lines (225 loc) · 6.29 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
const { queries } = require('./src/utils/algolia')
const isStaging = process.env.GATSBY_ACTIVE_ENV === 'staging'
const isProd = process.env.GATSBY_ACTIVE_ENV === 'production'
// These are useful to debug build issues
console.log(`
GATSBY_ACTIVE_ENV=${process.env.GATSBY_ACTIVE_ENV}
PR_NUMBER=${process.env.PR_NUMBER}
GATSBY_ALGOLIA_INDEX=${process.env.GATSBY_ALGOLIA_INDEX}
GATSBY_ALGOLIA_APP_ID=${process.env.GATSBY_ALGOLIA_APP_ID}
`)
if (isStaging && !process.env.PR_NUMBER && !process.env.GATSBY_PR_NUMBER) {
throw new Error("There's no PR_NUMBER to deploy to staging")
}
const plugins = [
{
resolve: 'gatsby-plugin-mdx',
options: {
remarkPlugins: [require('remark-slug'), require('remark-unwrap-images')],
gatsbyRemarkPlugins: [
{
resolve: 'gatsby-remark-relative-images',
},
{
resolve: 'gatsby-remark-images',
options: {
maxWidth: 640,
showCaptions: true,
},
},
'gatsby-remark-copy-linked-files',
],
},
},
'gatsby-plugin-theme-ui',
'gatsby-plugin-react-helmet',
'gatsby-plugin-typescript',
'gatsby-transformer-json',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'navigationData',
path: `${__dirname}/src/content/navigationData.json`,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'rootTopics',
path: `${__dirname}/autoGeneratedData/rootTopics.json`,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'secondLevelTopics',
path: `${__dirname}/autoGeneratedData/secondLevelTopics.json`,
},
},
{
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: ['UA-44750782-3', 'G-P12DWV2SBZ'],
pluginConfig: {
head: true,
},
},
},
{
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',
},
},
},
]
// Omit mdx images in fast dev mode
if (process.env.DEV_FAST !== 'true') {
plugins.push(
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'mdx-images',
path: `${__dirname}/src/content/images`,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/content/topics`,
name: 'mdx',
},
},
)
} else {
plugins.push({
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/content/topics`,
name: 'mdx',
// 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/metrics-and-insights',
],
},
})
}
if (isStaging || isProd) {
plugins.push(
{
// Only build algolia indexes in staging and production
resolve: 'gatsby-plugin-algolia',
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_KEY,
queries,
chunkSize: 10000, // default: 1000
continueOnFailure: isStaging,
enablePartialUpdates: true,
},
},
{
resolve: 'gatsby-plugin-s3',
options: {
bucketName: process.env.AWS_S3_BUCKET,
bucketPrefix: process.env.PR_NUMBER,
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,
},
},
)
}
if (isProd) {
plugins.push(
{
//https://www.gatsbyjs.org/packages/gatsby-plugin-segment-js/
resolve: 'gatsby-plugin-segment-js',
options: {
prodKey: process.env.SEGMENT_KEY,
//track pageviews when there is a route change. Calls window.analytics.page() on each route change.
trackPage: true,
delayLoad: false,
},
},
{
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')
}
// Push pr branches to a subfolder in the staging bucket using the pr number as routes.
// For example, a pr number 58 will be previewable on:
// https://docs-stg.launchdarkly.com/58
module.exports = {
pathPrefix: isStaging ? `/${process.env.PR_NUMBER}` : '/',
siteMetadata: {
title: 'LaunchDarkly Docs',
description: 'LaunchDarkly documentation',
author: '@launchdarkly',
siteUrl: 'https://docs.launchdarkly.com',
},
plugins,
}