{"id":35474642,"url":"https://github.com/rstackjs/rspack-plugin-react-refresh","last_synced_at":"2026-05-28T11:00:48.161Z","repository":{"id":252198401,"uuid":"839273938","full_name":"rstackjs/rspack-plugin-react-refresh","owner":"rstackjs","description":"React refresh plugin for Rspack.","archived":false,"fork":false,"pushed_at":"2026-05-13T13:51:30.000Z","size":421,"stargazers_count":19,"open_issues_count":5,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-05-13T15:38:14.348Z","etag":null,"topics":["react","react-refresh","rspack","rspack-plugin","rstack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/rstackjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-07T09:29:22.000Z","updated_at":"2026-05-10T16:52:07.000Z","dependencies_parsed_at":"2024-11-08T09:27:38.155Z","dependency_job_id":"3bc70f97-071d-4327-84f9-e9c607a8eb15","html_url":"https://github.com/rstackjs/rspack-plugin-react-refresh","commit_stats":null,"previous_names":["rspack-contrib/rspack-plugin-react-refresh","rstackjs/rspack-plugin-react-refresh"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/rstackjs/rspack-plugin-react-refresh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstackjs%2Frspack-plugin-react-refresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstackjs%2Frspack-plugin-react-refresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstackjs%2Frspack-plugin-react-refresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstackjs%2Frspack-plugin-react-refresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rstackjs","download_url":"https://codeload.github.com/rstackjs/rspack-plugin-react-refresh/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstackjs%2Frspack-plugin-react-refresh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33605379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","react-refresh","rspack","rspack-plugin","rstack"],"created_at":"2026-01-03T12:00:40.055Z","updated_at":"2026-05-28T11:00:48.156Z","avatar_url":"https://github.com/rstackjs.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Rspack Plugins"],"readme":"# @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## Versions\n\n- `2.x`: For Rspack v2.\n- `1.x`: For Rspack v1, see [v1.x - README](https://github.com/rstackjs/rspack-dev-server/tree/v1.x#rspackdev-server) for usage guide.\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## Import the plugin\n\nImport the plugin in your code:\n\n```js\nimport { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';\n```\n\n## Usage\n\nTo enable [React Fast Refresh](https://reactnative.dev/docs/fast-refresh), you need both runtime injection and source transformation.\n\n- This plugin handles runtime injection, including code from [react-refresh](https://www.npmjs.com/package/react-refresh) and the custom runtime it requires.\n- Source transformation should be enabled in your loader, for example with [jsc.transform.react.refresh](https://swc.rs/docs/configuration/compilation#jsctransformreactrefresh) in [swc-loader](https://rspack.rs/guide/features/builtin-swc-loader).\n\n```js\nimport { ReactRefreshRspackPlugin } from '@rspack/plugin-react-refresh';\n\nconst isDev = process.env.NODE_ENV === 'development';\n\nexport default {\n  mode: isDev ? 'development' : 'production',\n  module: {\n    rules: [\n      {\n        test: /\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,\n        use: {\n          loader: 'builtin:swc-loader',\n          options: {\n            detectSyntax: 'auto',\n            jsc: {\n              transform: {\n                react: {\n                  runtime: 'automatic',\n                  development: isDev,\n                  refresh: isDev,\n                },\n              },\n            },\n          },\n        },\n      },\n    ],\n  },\n  plugins: [isDev \u0026\u0026 new ReactRefreshRspackPlugin()],\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/rstackjs/rstack-examples/blob/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/rstackjs/rstack-examples/blob/main/rspack/react-refresh-babel-loader/rspack.config.js)\n\n## Options\n\n### test\n\n- Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)\n- Default: `/\\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/`\n\nSpecifies which files should be processed by the React Refresh loader. This option is passed to the `builtin:react-refresh-loader` as the `rule.test` condition.\n\nWorks identically to Rspack's [rule.test](https://rspack.rs/config/module-rules#rulestest) option.\n\n```js\nnew ReactRefreshPlugin({\n  test: [/\\.jsx$/, /\\.tsx$/],\n});\n```\n\n### include\n\n- Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)\n- Default: `undefined`\n\nExplicitly includes files to be processed by the React Refresh loader. This option is passed to the `builtin:react-refresh-loader` as the `rule.include` condition.\n\nUse this to limit processing to specific directories or file patterns.\n\nWorks identically to Rspack's [rule.include](https://rspack.rs/config/module-rules#rulesinclude) option.\n\n```js\nnew ReactRefreshPlugin({\n  include: [/\\.jsx$/, /\\.tsx$/],\n});\n```\n\n### exclude\n\n- Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)\n- Default: `/node_modules/`\n\nExclude files from being processed by the plugin. The value is the same as the [rule.exclude](https://rspack.rs/config/module-rules#rulesexclude) option in Rspack.\n\n```js\nnew ReactRefreshPlugin({\n  exclude: [/node_modules/, /some-other-module/],\n});\n```\n\n### resourceQuery\n\n- Type: [Rspack.RuleSetCondition](https://rspack.rs/config/module-rules#condition)\n- Default: `undefined`\n\nCan be used to exclude certain resources from being processed by the plugin by the resource query. The value is the same as the [rule.resourceQuery](https://rspack.rs/config/module-rules#rulesresourcequery) option in Rspack.\n\nFor example, to exclude all resources with the `raw` query, such as `import rawTs from './ReactComponent.ts?raw';`, use the following:\n\n```js\nnew ReactRefreshPlugin({\n  resourceQuery: { not: /raw/ },\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### reloadOnRuntimeErrors\n\n- Type: `boolean`\n- Default: `false`\n\nConfig the plugin whether trigger a full page reload when an unrecoverable runtime error is encountered.\n\nCurrently, only module factory undefined error is considered as unrecoverable runtime error.\n\n```js\nnew ReactRefreshPlugin({\n  reloadOnRuntimeErrors: true,\n});\n```\n\n### reactRefreshLoader\n\n- Type: `string`\n- Default: `builtin:react-refresh-loader`\n\nBy default, the plugin uses the `builtin:react-refresh-loader` loader implementation [from Rspack](https://github.com/web-infra-dev/rspack/tree/main/crates/rspack_loader_react_refresh) to inject the React Refresh utilities into each module. The `reactRefreshLoader` option allows you to specify a loader that implements custom React Refresh instrumentation if needed.\n\n```js\nnew ReactRefreshPlugin({\n  reactRefreshLoader: 'my-advanced-react-refresh-loader',\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstackjs%2Frspack-plugin-react-refresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frstackjs%2Frspack-plugin-react-refresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstackjs%2Frspack-plugin-react-refresh/lists"}