-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathgatsby-node.js
39 lines (33 loc) · 1.07 KB
/
gatsby-node.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
const path = require(`path`)
let didRunAlready = false
let absoluteLocaleDirectory
exports.onPreInit = ({ store }, { defaultLocale }) => {
// defaultLocale must be defined, no default option will be defined
if (!defaultLocale) {
throw new Error(`
Please define the 'defaultLocale' option of gatsby-theme-i18n-react-intl
`)
}
const localesPath = path.join(
store.getState().program.directory,
defaultLocale
)
if (didRunAlready) {
throw new Error(
`You can only have single instance of gatsby-theme-i18n-react-intl in your gatsby-config.js`
)
}
didRunAlready = true
// The defaultLocale is the path to a file, but since we want to require multiple json files
// this should really be the directory where the files are located, thus path.dirname
absoluteLocaleDirectory = path.dirname(localesPath)
}
exports.onCreateWebpackConfig = ({ actions, plugins }) => {
actions.setWebpackConfig({
plugins: [
plugins.define({
GATSBY_THEME_I18N_REACT_INTL: JSON.stringify(absoluteLocaleDirectory),
}),
],
})
}