next.js/packages/react-refresh-utils/ReactRefreshRspackPlugin.ts
ReactRefreshRspackPlugin.ts25 lines686 B
import type { Compiler } from 'webpack'

const PLUGIN_NAME = 'ReactRefreshRspackPlugin'

class ReactRefreshRspackPlugin {
  static loader = 'builtin:react-refresh-loader'

  apply(compiler: Compiler) {
    new compiler.webpack.ProvidePlugin({
      $ReactRefreshRuntime$: require.resolve('./internal/RspackReactRefresh'),
    }).apply(compiler)

    compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
      compilation.hooks.additionalTreeRuntimeRequirements.tap(
        PLUGIN_NAME,
        (_, runtimeRequirements) => {
          runtimeRequirements.add(compiler.webpack.RuntimeGlobals.moduleCache)
        }
      )
    })
  }
}

export default ReactRefreshRspackPlugin
Quest for Codev2.0.0
/
SIGN IN