{"id":14054194,"url":"https://github.com/rspack-contrib/rspack-plugin-react-refresh","last_synced_at":"2025-04-08T03:21:05.990Z","repository":{"id":252198401,"uuid":"839273938","full_name":"rspack-contrib/rspack-plugin-react-refresh","owner":"rspack-contrib","description":"React refresh plugin for Rspack.","archived":false,"fork":false,"pushed_at":"2025-03-01T07:31:25.000Z","size":268,"stargazers_count":16,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T19:43:58.742Z","etag":null,"topics":["react","rspack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rspack-contrib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-07T09:29:22.000Z","updated_at":"2025-03-29T12:39:51.000Z","dependencies_parsed_at":"2024-11-08T09:27:38.155Z","dependency_job_id":"3bc70f97-071d-4327-84f9-e9c607a8eb15","html_url":"https://github.com/rspack-contrib/rspack-plugin-react-refresh","commit_stats":null,"previous_names":["rspack-contrib/rspack-plugin-react-refresh"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frspack-plugin-react-refresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frspack-plugin-react-refresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frspack-plugin-react-refresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frspack-plugin-react-refresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rspack-contrib","download_url":"https://codeload.github.com/rspack-contrib/rspack-plugin-react-refresh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767405,"owners_count":20992586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react","rspack"],"created_at":"2024-08-12T21:00:56.123Z","updated_at":"2025-04-08T03:21:05.967Z","avatar_url":"https://github.com/rspack-contrib.png","language":"JavaScript","readme":"\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://assets.rspack.dev/rspack/rspack-banner-plain-dark.png\"\u003e\n  \u003cimg alt=\"Rspack Banner\" src=\"https://assets.rspack.dev/rspack/rspack-banner-plain-light.png\"\u003e\n\u003c/picture\u003e\n\n# @rspack/plugin-react-refresh\n\n\u003cp\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@rspack/plugin-react-refresh?activeTab=readme\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@rspack/plugin-react-refresh?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"npm version\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/@rspack/plugin-react-refresh?minimal=true\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@rspack/plugin-react-refresh.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"downloads\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/web-infra-dev/rspack/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"license\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nReact refresh plugin for [Rspack](https://github.com/web-infra-dev/rspack).\n\n## Installation\n\nFirst you need to install this plugin and its dependencies:\n\n```bash\nnpm add @rspack/plugin-react-refresh react-refresh -D\n# or\nyarn add @rspack/plugin-react-refresh react-refresh -D\n# or\npnpm add @rspack/plugin-react-refresh react-refresh -D\n# or\nbun add @rspack/plugin-react-refresh react-refresh -D\n```\n\n## Usage\n\nEnabling [React Fast Refresh](https://reactnative.dev/docs/fast-refresh) functionality primarily involves two aspects: code injection and code transformation.\n\n- Code injection will inject some code from the [react-refresh](https://www.npmjs.com/package/react-refresh) package, as well as some custom runtime code, all of which are integrated in this plugin and can be injected through.\n- Code transformation can be added through loaders, such as [jsc.transform.react.refresh](https://swc.rs/docs/configuration/compilation#jsctransformreactrefresh) for [swc-loader](https://swc.rs/docs/usage/swc-loader) or the [react-refresh/babel](https://github.com/facebook/react/tree/main/packages/react-refresh) for [babel-loader](https://github.com/babel/babel-loader).\n\n```js\nconst ReactRefreshPlugin = require(\"@rspack/plugin-react-refresh\");\nconst isDev = process.env.NODE_ENV === \"development\";\n\nmodule.exports = {\n  experiments: {\n    rspackFuture: {\n      disableTransformByDefault: true,\n    },\n  },\n  // ...\n  mode: isDev ? \"development\" : \"production\",\n  module: {\n    rules: [\n      {\n        test: /\\.jsx$/,\n        use: {\n          loader: \"builtin:swc-loader\",\n          options: {\n            jsc: {\n              parser: {\n                syntax: \"ecmascript\",\n                jsx: true,\n              },\n              transform: {\n                react: {\n                  development: isDev,\n                  refresh: isDev,\n                },\n              },\n            },\n          },\n        },\n      },\n    ],\n  },\n  plugins: [isDev \u0026\u0026 new ReactRefreshPlugin()].filter(Boolean),\n};\n```\n\nCompared to the previous approach, this method decouples the React Fast Refresh code injection logic from the transformation logic. The code injection logic is handled uniformly by this plugin, while the code transformation is handled by loaders. This means that this plugin can be used in conjunction with `builtin:swc-loader`, `swc-loader`, or `babel-loader`.\n\n## Example\n\n- For usage with `builtin:swc-loader`, you can refer to the example at [examples/react-refresh](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/react-refresh/rspack.config.js), When using with `swc-loader`, simply replace `builtin:swc-loader` with `swc-loader`.\n- For usage with `babel-loader`, you can refer to the example at [examples/react-refresh-babel-loader](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/react-refresh-babel-loader/rspack.config.js)\n\n## Options\n\n### include\n\n- Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)\n- Default: `/\\.([cm]js|[jt]sx?|flow)$/i`\n\nInclude files to be processed by the plugin. The value is the same as the `rule.test` option in Rspack.\n\n```js\nnew ReactRefreshPlugin({\n  include: [/\\.jsx$/, /\\.tsx$/],\n});\n```\n\n### exclude\n\n- Type: [Rspack.RuleSetCondition](https://rspack.dev/config/module#condition)\n- Default: `/node_modules/`\n\nExclude files from being processed by the plugin. The value is the same as the `rule.exclude` option in Rspack.\n\n```js\nnew ReactRefreshPlugin({\n  exclude: [/node_modules/, /some-other-module/],\n});\n```\n\n### forceEnable\n\n- Type: `boolean`\n- Default: `false`\n\nWhether to force enable the plugin.\n\nBy default, the plugin will not be enabled in non-development environments. If you want to force enable the plugin, you can set this option to `true`.\n\n```js\nnew ReactRefreshPlugin({\n  forceEnable: true,\n});\n```\n\nIt is useful if you want to:\n\n- Use the plugin in production.\n- Use the plugin with the `none` mode without setting `NODE_ENV`.\n- Use the plugin in environments we do not support, such as `electron-prerender` (**WARNING: Proceed at your own risk**).\n\n### library\n\n- Type: `string`\n- Default: `output.uniqueName || output.library`\n\nSets a namespace for the React Refresh runtime.\n\nIt is most useful when multiple instances of React Refresh is running together simultaneously.\n\n### overlay\n\n- Type: `boolean | OverlayOptions`\n- Default: `false`\n\nModify the behavior of the error overlay.\n\nCheckout [OverlayOptions](https://github.com/rspack-contrib/rspack-plugin-react-refresh/blob/main/src/options.ts#L4) type signature for more details.\n\n- Enable the error overlay:\n\n```js\nnew ReactRefreshPlugin({\n  overlay: true,\n});\n```\n\n- Configure the error overlay:\n\n```js\nnew ReactRefreshPlugin({\n  overlay: {\n    // ...\n  },\n});\n```\n\n## Credits\n\nThanks to the [react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) created by [@pmmmwh](https://github.com/pmmmwh), which inspires implement this plugin.\n\n## License\n\n`@rspack/plugin-react-refresh` is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).\n","funding_links":[],"categories":["Plugins"],"sub_categories":["Rspack Plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frspack-contrib%2Frspack-plugin-react-refresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frspack-contrib%2Frspack-plugin-react-refresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frspack-contrib%2Frspack-plugin-react-refresh/lists"}