-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
gatsby-node.js
56 lines (50 loc) · 1.5 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
const resolvableExtensions = () => [`.ts`, `.tsx`]
function onCreateBabelConfig({ actions }, options) {
actions.setBabelPreset({
name: require.resolve(`@babel/preset-typescript`),
options,
})
actions.setBabelPlugin({
name: require.resolve(`@babel/plugin-proposal-optional-chaining`),
})
actions.setBabelPlugin({
name: require.resolve(`@babel/plugin-proposal-nullish-coalescing-operator`),
})
actions.setBabelPlugin({
name: require.resolve(`@babel/plugin-proposal-numeric-separator`),
})
}
function onCreateWebpackConfig({ actions, loaders }) {
const jsLoader = loaders.js()
if (!jsLoader) {
return
}
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.tsx?$/,
use: jsLoader,
},
],
},
})
}
if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) {
exports.pluginOptionsSchema = ({ Joi }) =>
Joi.object({
isTSX: Joi.boolean().description(`Enables jsx parsing.`).default(false),
jsxPragma: Joi.string()
.description(
`Replace the function used when compiling JSX expressions.`
)
.default(`React`),
allExtensions: Joi.boolean()
.description(`Indicates that every file should be parsed as TS or TSX.`)
.default(false)
.when(`isTSX`, { is: true, then: Joi.valid(true) }),
})
}
exports.resolvableExtensions = resolvableExtensions
exports.onCreateBabelConfig = onCreateBabelConfig
exports.onCreateWebpackConfig = onCreateWebpackConfig