Skip to content

Commit

Permalink
Fix incompatibility with TS plugin
Browse files Browse the repository at this point in the history
TypeScript plugin for Gatsby doesn't use `include` or `exclude` at all,
so now we're simply matchin all TS rules.

Fix #13.
  • Loading branch information
silvenon committed May 27, 2019
1 parent 17e7a4f commit 106f886
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const TYPESCRIPT_RULE_TEST = '\\.tsx?$'
const TS_RULE_TEST = '\\.tsx?$'

exports.onCreateWebpackConfig = ({ actions, getConfig, rules, stage }) => {
const { replaceWebpackConfig } = actions
const config = getConfig()

const tests = [rules.js().test.source, TYPESCRIPT_RULE_TEST]
const JS_RULE_TEST = rules.js().test.source

const sourceRules = config.module.rules.filter(({ test, exclude }) => {
if (!test || !exclude) return false
const sourceRules = config.module.rules.filter(({ test, include }) => {
if (!test) return false
return (
tests.includes(test.source) && exclude.source.includes('node_modules')
(test.source === JS_RULE_TEST &&
include != null &&
!include.source.includes('node_modules')) ||
test.source === TS_RULE_TEST
)
})

Expand All @@ -26,7 +29,7 @@ exports.onCreateWebpackConfig = ({ actions, getConfig, rules, stage }) => {
displayName: stage.includes('develop'),
babelOptions: {
presets:
rule.test.source === TYPESCRIPT_RULE_TEST
rule.test.source === TS_RULE_TEST
? ['babel-preset-gatsby', '@babel/preset-typescript']
: ['babel-preset-gatsby'],
},
Expand Down

0 comments on commit 106f886

Please sign in to comment.