Skip to content

Commit

Permalink
feat(plugin-react-refresh): support configure babel plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored and aleclarson committed May 28, 2021
1 parent 5745a2e commit 3924e3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/plugin-react-refresh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export default {
}
```

## Specifying Additional Babel Plugins

```js
export default {
plugins: [reactRefresh({
plugins: ['@emotion/babel-plugin']
})]
}
```

[Full list of Babel parser plugins](https://babeljs.io/docs/en/babel-parser#ecmascript-proposalshttpsgithubcombabelproposals).

### Notes
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-react-refresh/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check
const fs = require('fs')
const { transformSync, ParserOptions } = require('@babel/core')

const runtimePublicPath = '/@react-refresh'
const runtimeFilePath = require.resolve(
'react-refresh/cjs/react-refresh-runtime.development.js'
Expand Down Expand Up @@ -96,7 +95,7 @@ function reactRefreshPlugin(opts) {
// commonly used with TS.
parserPlugins.push('typescript', 'decorators-legacy')
}
if (opts && opts.parserPlugins) {
if (opts && Array.isArray(opts.parserPlugins)) {
parserPlugins.push(...opts.parserPlugins)
}

Expand All @@ -116,7 +115,8 @@ function reactRefreshPlugin(opts) {
plugins: [
require('@babel/plugin-transform-react-jsx-self'),
require('@babel/plugin-transform-react-jsx-source'),
[require('react-refresh/babel'), { skipEnvCheck: true }]
[require('react-refresh/babel'), { skipEnvCheck: true }],
...(opts && Array.isArray(opts.plugins) ? opts.plugins : [])
],
ast: !isReasonReact,
sourceMaps: true,
Expand Down

0 comments on commit 3924e3d

Please sign in to comment.