-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
Copy pathgatsby-node.js
74 lines (69 loc) · 2.28 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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 }) {
if (typeof loaders?.js !== `function`) {
return
}
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.tsx?$/,
use: ({ resourceQuery, issuer }) => [
loaders.js({
isPageTemplate: /async-requires/.test(issuer),
resourceQuery,
}),
],
},
],
},
})
}
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`),
jsxPragmaFrag: Joi.string()
.description(
`Replace the function used when compiling JSX fragment expressions.`
)
.optional(),
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) }),
allowNamespaces: Joi.boolean()
.description(`Enables compilation of TypeScript namespaces.`)
.optional(),
allowDeclareFields: Joi.boolean()
.description(
`When enabled, type-only class fields are only removed if they are prefixed with the declare modifier.`
)
.optional(),
onlyRemoveTypeImports: Joi.boolean()
.description(
`When set to true, the transform will only remove type-only imports (introduced in TypeScript 3.8).` +
`This should only be used if you are using TypeScript >= 3.8.`
)
.optional(),
})
exports.resolvableExtensions = resolvableExtensions
exports.onCreateBabelConfig = onCreateBabelConfig
exports.onCreateWebpackConfig = onCreateWebpackConfig