MCPcopy
hub / github.com/web-infra-dev/rsbuild / pluginReact

Function pluginReact

packages/plugin-react/src/index.ts:158–253  ·  view source on GitHub ↗
(options: PluginReactOptions = {})

Source from the content-addressed store, hash-verified

156}
157
158export const pluginReact = (options: PluginReactOptions = {}): RsbuildPlugin => ({
159 name: PLUGIN_REACT_NAME,
160
161 setup(api) {
162 assertCoreVersion(api.context.version);
163
164 const defaultOptions = {
165 fastRefresh: true,
166 splitChunks: true,
167 enableProfiler: false,
168 } satisfies PluginReactOptions;
169
170 const finalOptions = {
171 ...defaultOptions,
172 ...options,
173 };
174
175 if (finalOptions.reactCompiler !== undefined) {
176 assertReactCompilerVersion();
177 }
178
179 const reactRefreshPath = finalOptions.fastRefresh ? require.resolve('react-refresh') : '';
180
181 api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig }) => {
182 const isDev = config.mode === 'development';
183 const usingHMR = isDev && config.dev.hmr && config.output.target === 'web';
184
185 const reactOptions: Rspack.SwcLoaderTransformConfig['react'] = {
186 development: isDev,
187 refresh: usingHMR && finalOptions.fastRefresh,
188 runtime: 'automatic',
189 ...finalOptions.swcReactOptions,
190 };
191 const transformOptions: Rspack.SwcLoaderTransformConfig = {
192 react: reactOptions,
193 };
194
195 if (finalOptions.reactCompiler !== undefined) {
196 transformOptions.reactCompiler = finalOptions.reactCompiler;
197 }
198
199 return mergeEnvironmentConfig(
200 {
201 tools: {
202 swc: {
203 jsc: {
204 transform: transformOptions,
205 },
206 },
207 },
208 },
209 config,
210 );
211 });
212
213 if (finalOptions.swcReactOptions?.runtime === 'preserve') {
214 api.modifyBundlerChain((chain) => {
215 chain.module.parser.merge({

Callers 15

index.test.tsFile · 0.90
rsbuild.config.jsFile · 0.90
rsbuild.config.tsFile · 0.90
index.test.tsFile · 0.90
features.test.tsFile · 0.90
rsbuild.config.tsFile · 0.90
rsbuild.config.tsFile · 0.90
rsbuild.config.tsFile · 0.90
rsbuild.config.tsFile · 0.90
rsbuild.config.tsFile · 0.90
rsbuild.config.tsFile · 0.90
rsbuild.config.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…