Skip to content

Commit

Permalink
refactor: reactRefreshLoader (#863)
Browse files Browse the repository at this point in the history
* chore: rename to reactRefreshLoader

* chore: make loader cacheable

* docs: add loader docs
  • Loading branch information
jbroma authored Jan 12, 2025
1 parent 3cebacd commit 23779e4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 0 additions & 4 deletions packages/repack/src/loaders/reactRefreshCompatLoader/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/repack/src/loaders/reactRefreshLoader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import reactRefreshLoader, { raw } from './reactRefreshLoader.js';

export { raw };
export default reactRefreshLoader;
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ export const raw = false;
*
* Reference implementation: https://github.com/web-infra-dev/rspack/blob/main/crates/rspack_loader_react_refresh/src/lib.rs
*/
export default function reactRefreshCompatLoader(
export default function reactRefreshLoader(
this: LoaderContext,
originalSource: string,
sourceMap: any,
meta: any
) {
this.cacheable();
const callback = this.async();

const source = `${originalSource}\n\n${reactRefreshFooter}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/repack/src/plugins/DevelopmentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DevelopmentPlugin implements RspackPluginInstance {
fallback: {
...compiler.options.resolveLoader?.fallback,
'builtin:react-refresh-loader': require.resolve(
'../loaders/reactRefreshCompatLoader'
'../loaders/reactRefreshLoader'
),
},
};
Expand Down
22 changes: 21 additions & 1 deletion website/src/5.x/api/loaders/react-refresh-loader.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# ReactRefreshCompatLoader
# ReactRefreshLoader

The `ReactRefreshLoader` is a fallback loader for Webpack that provides React Refresh functionality, mimicking the behavior of Rspack's built-in `builtin:react-refresh-loader`.

## Example

```js title=webpack.config.cjs
module.exports = {
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: {
loader: "@callstack/repack/react-refresh-loader",
},
},
],
},
};
```

0 comments on commit 23779e4

Please sign in to comment.