diff --git a/packages/cli/builder/src/rspack/index.ts b/packages/cli/builder/src/rspack/index.ts index 49ae6eee545b..fec11e52d099 100644 --- a/packages/cli/builder/src/rspack/index.ts +++ b/packages/cli/builder/src/rspack/index.ts @@ -6,6 +6,7 @@ import type { } from '@rsbuild/core'; import type { PluginBabelOptions } from '@rsbuild/plugin-babel'; import { parseCommonConfig } from '../shared/parseCommonConfig'; +import { pluginNativeWatcher } from '../shared/plugins/nativeWatcher'; import { rsbuildRscPlugin } from '../shared/rsc/plugins/rsbuild-rsc-plugin'; import { castArray } from '../shared/utils'; import type { @@ -121,6 +122,8 @@ export async function parseConfig( ); } + rsbuildPlugins.push(pluginNativeWatcher()); + return { rsbuildConfig, rsbuildPlugins, @@ -148,6 +151,8 @@ export async function createRspackBuilder( // builder plugins should be registered earlier than user plugins rsbuildConfig.plugins = [...rsbuildPlugins, ...(rsbuildConfig.plugins || [])]; + // rsbuildPlugins.push + const rsbuild = await createRsbuild({ cwd, rsbuildConfig, diff --git a/packages/cli/builder/src/shared/plugins/nativeWatcher.ts b/packages/cli/builder/src/shared/plugins/nativeWatcher.ts new file mode 100644 index 000000000000..0bd25bc7ced1 --- /dev/null +++ b/packages/cli/builder/src/shared/plugins/nativeWatcher.ts @@ -0,0 +1,17 @@ +import type { RsbuildPlugin } from '@rsbuild/core'; + +/** + * Enable native watcher for Rspack. + */ +export const pluginNativeWatcher = (): RsbuildPlugin => ({ + name: 'builder:native-watcher', + + setup(api) { + api.modifyRspackConfig(config => { + config.experiments = { + ...(config.experiments || {}), + nativeWatcher: true, + }; + }); + }, +}); diff --git a/packages/cli/builder/tests/__snapshots__/default.test.ts.snap b/packages/cli/builder/tests/__snapshots__/default.test.ts.snap index 1de6f3c3d81b..cca638e073ba 100644 --- a/packages/cli/builder/tests/__snapshots__/default.test.ts.snap +++ b/packages/cli/builder/tests/__snapshots__/default.test.ts.snap @@ -12,6 +12,7 @@ exports[`builder rspack > should generator rspack config correctly 1`] = ` }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false, @@ -1281,6 +1282,7 @@ exports[`builder rspack > should generator rspack config correctly 2`] = ` "rsbuild:svgr", "rsbuild:css-minimizer", "builder:postcss-plugins", + "builder:native-watcher", "user-plugin", ] `; @@ -1296,6 +1298,7 @@ exports[`builder rspack > should generator rspack config correctly when node 1`] }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false, @@ -2141,6 +2144,7 @@ exports[`builder rspack > should generator rspack config correctly when prod 1`] }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false, @@ -3419,6 +3423,7 @@ exports[`builder rspack > should generator rspack config correctly when service- }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false, diff --git a/packages/cli/builder/tests/__snapshots__/environment.test.ts.snap b/packages/cli/builder/tests/__snapshots__/environment.test.ts.snap index bb2a6e5efe4d..86da2f9a811b 100644 --- a/packages/cli/builder/tests/__snapshots__/environment.test.ts.snap +++ b/packages/cli/builder/tests/__snapshots__/environment.test.ts.snap @@ -13,6 +13,7 @@ exports[`builder environment compat > should generator environment config correc }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false, @@ -1255,6 +1256,7 @@ exports[`builder environment compat > should generator environment config correc }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false, @@ -2061,6 +2063,7 @@ exports[`builder environment compat > should generator environment config correc }, "experiments": { "asyncWebAssembly": true, + "nativeWatcher": true, "rspackFuture": { "bundlerInfo": { "force": false,