web-infra-dev / rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.
https://rsbuild.dev/
MIT License
1.82k stars 140 forks source link

[Bug]: `tools.swc.jsc.transform.react` config overrides takes no effect #3418

Closed SoonIter closed 2 months ago

SoonIter commented 2 months ago

Version

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 67.98 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 128.0.6613.120
    Chrome Canary: 130.0.6702.0
    Safari: 17.6
  npmPackages:
    @rsbuild/core: 1.0.1-rc.5 => 1.0.1-rc.5 
    @rsbuild/plugin-react: 1.0.1-rc.5 => 1.0.1-rc.5

Details

  1. rsbuild.config.ts
export default defineConfig({
  plugins: [pluginReact()],
  tools: {
    swc: {
      jsc: {
        transform: {
          react: {
            runtime: 'classic',
          },
        },
      },
    },
  },
});
  1. DEBUG=rsbuild rsbuild build
image

Reproduce link

https://github.com/SoonIter/rsbuild-tools-swc-issue-repro

Reproduce Steps

https://github.com/web-infra-dev/rsbuild/blob/14c5a9e3bedba919244818792c238a51f2acefe5/packages/core/src/plugins/swc.ts#L158

  1. pnpm install
  2. DEBUG=rsbuild npx rsbuild build
SoonIter commented 2 months ago

overrided by @rsbuild/plugin-react

fixed by

export default defineConfig({
  plugins: [pluginReact({
    swcReactOptions: {
      runtime: 'classic'
    }
  })],
  tools: {
    // swc(config) {
    //   (((config.jsc ??= {}).transform ??= {}).react ??= {}).runtime =
    //     'classic';
    // },
  },
});
SoonIter commented 2 months ago

tools.swc should execute in the final stage just like tools.bundlerChain and tools.rspack

so pluginSwc should execute after pluginReact?

modernjs has no entry for modifying the options of pluginReact

@chenjiahan cc

chenjiahan commented 2 months ago

This is an order issue, I think we can try to let pluginReact to use tools.swc instead of using modifySwcLoaderOptions

SoonIter commented 2 months ago

This is an order issue, I think we can try to let pluginReact to use tools.swc instead of using modifySwcLoaderOptions

I cannot get isDev usingHMR in modifyRsbuildConfig 😂...

chenjiahan commented 2 months ago

Yes, let me think if there is a better way...