-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
56 lines (48 loc) · 1.17 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
46
47
48
49
50
51
52
53
54
55
56
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// https://github.com/silvenon/gatsby-plugin-linaria
// https://www.gatsbyjs.org/docs/add-custom-webpack-config/
const TS_RULE_TEST = "\\.tsx?$"
exports.onCreateWebpackConfig = ({
actions,
getConfig,
rules,
stage,
loaders,
plugins,
}) => {
const config = getConfig()
// const isDevelop = stage.startsWith("develop")
const usingTS = config.module.rules.some(
({ test }) => test && test.source === TS_RULE_TEST
)
// const existingTsRule = config.module.rules.find(
// ({ test }) => test && test.source === TS_RULE_TEST
// )
const primitivesLoader = {
loader: "chronstruct-primitives/loader",
options: {
autoImport: true,
},
}
// const jsRule = {
// ...rules.js(),
// use: [primitivesLoader],
// }
const tsRule = usingTS && {
test: new RegExp(TS_RULE_TEST),
use: [primitivesLoader],
}
actions.setWebpackConfig({
module: {
rules: [/*jsRule,*/ tsRule].filter(Boolean),
},
})
// const configAfter = getConfig()
// configAfter.module.rules.forEach(rule => {
// console.log(rule)
// })
}