Skip to content

Commit

Permalink
feat(gatsby-plugin-typescript): allow specifying babel preset options (
Browse files Browse the repository at this point in the history
…#10248)

* Pass through babel preset options

* Add options section to gatsby-plugin-typescript docs

* format
  • Loading branch information
colebemis authored and pieh committed Dec 4, 2018
1 parent f95a9d7 commit f106241
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/gatsby-plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ module.exports = {
}
```

## Options

When adding this plugin to your `gatsby-config.js`, you can pass in options to override the default [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript#options) config.

```javascript
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-typescript`,
options: {
isTSX: true, // defaults to false
jsxPragma: `jsx`, // defaults to "React"
allExtensions: true, // defaults to false
},
},
],
}
```

For more detailed documentation on the available options, visit https://babeljs.io/docs/en/babel-preset-typescript#options.

## Caveats

This plugin uses [`babel-plugin-transform-typescript`](https://babeljs.io/docs/en/babel-plugin-transform-typescript.html)
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-typescript/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const resolvableExtensions = () => [`.ts`, `.tsx`]

function onCreateBabelConfig({ actions }, pluginOptions) {
function onCreateBabelConfig({ actions }, options) {
actions.setBabelPreset({
name: `@babel/preset-typescript`,
options,
})
}

Expand Down

0 comments on commit f106241

Please sign in to comment.