forked from chitoku-k/gatsby-plugin-ts-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
44 lines (43 loc) · 1.1 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
// Tell webpack it can resolve this file types
exports.resolvableExtensions = () => [".ts", ".tsx", ".js", ".jsx"];
exports.onCreateWebpackConfig = (
{
stage,
getConfig,
rules,
loaders,
plugins,
actions /* destructured Object that gatsby provides to plugins*/
},
{ tslint /* destructured plugin options*/ }
) => {
const config = {
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
// Feed the compiled ts files through babel
use: [loaders.js(), require.resolve("ts-loader")]
}
]
}
};
// If typescript is enabled add it to the rules
if (tslint) {
const tslintRules = {
test: /\.tsx?$/,
enforce: "pre",
exclude: /(node_modules|cache|public)/,
use: [
{
loader: require.resolve("tslint-loader"),
options: { emitErrors: stage === "build-javascript" }
}
]
};
config.module.rules = [...config.module.rules, tslintRules];
}
// Merge the typescript config into the default webpack config
actions.setWebpackConfig(config);
};