Skip to content

Commit

Permalink
feat(plugin-react-refresh): support configure babel plugins
Browse files Browse the repository at this point in the history
fix: #3276
  • Loading branch information
underfin authored and aleclarson committed Sep 17, 2021
1 parent b9e837a commit 8cfd71e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 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).

## Specifying files to include or exclude from refreshing
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-react-refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs')
const { transformSync, ParserOptions } = require('@babel/core')
const { createFilter } = require('@rollup/pluginutils')

const runtimePublicPath = '/@react-refresh'
const runtimeFilePath = require.resolve(
'react-refresh/cjs/react-refresh-runtime.development.js'
Expand Down Expand Up @@ -100,7 +101,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 @@ -120,7 +121,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 8cfd71e

Please sign in to comment.