A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rspack-contrib/rspack-plugin-react-refresh below:

rspack-contrib/rspack-plugin-react-refresh: React refresh plugin for Rspack.

@rspack/plugin-react-refresh

React refresh plugin for Rspack.

First you need to install this plugin and its dependencies:

npm add @rspack/plugin-react-refresh react-refresh -D
# or
yarn add @rspack/plugin-react-refresh react-refresh -D
# or
pnpm add @rspack/plugin-react-refresh react-refresh -D
# or
bun add @rspack/plugin-react-refresh react-refresh -D

Import the plugin in your code:

// Named import (recommended)
import { ReactRefreshRspackPlugin } from "@rspack/plugin-react-refresh";
const ReactRefreshRspackPlugin = require("@rspack/plugin-react-refresh");

Enabling React Fast Refresh functionality primarily involves two aspects: code injection and code transformation.

const ReactRefreshPlugin = require("@rspack/plugin-react-refresh");
const isDev = process.env.NODE_ENV === "development";

module.exports = {
  experiments: {
    rspackFuture: {
      disableTransformByDefault: true,
    },
  },
  // ...
  mode: isDev ? "development" : "production",
  module: {
    rules: [
      {
        test: /\.jsx$/,
        use: {
          loader: "builtin:swc-loader",
          options: {
            jsc: {
              parser: {
                syntax: "ecmascript",
                jsx: true,
              },
              transform: {
                react: {
                  development: isDev,
                  refresh: isDev,
                },
              },
            },
          },
        },
      },
    ],
  },
  plugins: [isDev && new ReactRefreshPlugin()].filter(Boolean),
};

Compared 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.

Include files to be processed by the plugin. The value is the same as the rule.test option in Rspack.

new ReactRefreshPlugin({
  include: [/\.jsx$/, /\.tsx$/],
});

Exclude files from being processed by the plugin. The value is the same as the rule.exclude option in Rspack.

new ReactRefreshPlugin({
  exclude: [/node_modules/, /some-other-module/],
});

Can 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 option in Rspack.

For example, to exclude all resources with the raw query, such as import rawTs from './ReactComponent.ts?raw';, use the following:

new ReactRefreshPlugin({
  resourceQuery: { not: /raw/ },
});

Whether to force enable the plugin.

By 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.

new ReactRefreshPlugin({
  forceEnable: true,
});

It is useful if you want to:

Sets a namespace for the React Refresh runtime.

It is most useful when multiple instances of React Refresh is running together simultaneously.

Modify the behavior of the error overlay.

Checkout OverlayOptions type signature for more details.

new ReactRefreshPlugin({
  overlay: true,
});
new ReactRefreshPlugin({
  overlay: {
    // ...
  },
});

Thanks to the react-refresh-webpack-plugin created by @pmmmwh, which inspires implement this plugin.

@rspack/plugin-react-refresh is MIT licensed.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4