-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
gatsby-node.js
45 lines (38 loc) · 1.15 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
40
41
42
43
44
45
const fs = require(`fs`)
const path = require(`path`)
const os = require(`os`)
// Write out a typography module to .cache.
exports.onPreBootstrap = ({ store, cache }, pluginOptions) => {
const program = store.getState().program
let module
if (pluginOptions.pathToConfigModule) {
module = `module.exports = require("${
path.isAbsolute(pluginOptions.pathToConfigModule)
? pluginOptions.pathToConfigModule
: path.join(program.directory, pluginOptions.pathToConfigModule)
}")`
if (os.platform() === `win32`) {
module = module.split(`\\`).join(`\\\\`)
}
} else {
module = `const Typography = require("typography")
const typography = new Typography()
module.exports = typography`
}
const dir = cache.directory
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
fs.writeFileSync(path.join(dir, `typography.js`), module)
}
exports.onCreateWebpackConfig = ({ actions, cache }) => {
const cacheFile = path.join(cache.directory, `typography.js`)
const { setWebpackConfig } = actions
setWebpackConfig({
resolve: {
alias: {
"typography-plugin-cache-endpoint": cacheFile,
},
},
})
}