web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.19k stars 108 forks source link

[Bug]: `DEBUG=rsbuild rspress build` will delete the generated `rspack.config.node.js` #1167

Open SoonIter opened 2 weeks ago

SoonIter commented 2 weeks ago

Version

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 78.64 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 125.0.6422.142
    Chrome Canary: 127.0.6533.0
    Safari: 17.5
  npmPackages:
    rspress: workspace:* => 1.23.1

Details

when running DEBUG=rsbuild rsbuild build under the rsbuild project with output.targets = ['web', 'node']

success Inspect config succeed, open following files to view the content: 

  - Rsbuild Config: /demo/dist/rsbuild.config.mjs
  - Rspack Config (web):/demo/dist/rspack.config.web.mjs
  - Rspack Config (node): /demo/dist/rspack.config.node.mjs

● Client ━━━━━━━━━━━━━━━━━━━━━━━━━ (100%) emitting after emit   

ready   Client compiled in 0.17 s
ready   Server compiled in 0.08 s

when running DEBUG=rsbuild rspress build

success Inspect config succeed, open following files to view the content: 

  - Rsbuild Config:/demo/doc_build/rsbuild.config.mjs
  - Rspack Config (node): /demo/rspack.config.node.mjs

success Inspect config succeed, open following files to view the content: 

  - Rsbuild Config:  /demo/doc_build/rsbuild.config.mjs
  - Rspack Config (web):  /demo/doc_build/rspack.config.web.mjs

ready   Server compiled in 0.41 s
ready   Client compiled in 0.36 s

and /demo/rspack.config.node.mjs will be deleted

related to https://rspress.dev/api/config/config-build#default-config

For better DEBUG mode under rspress, this part of the code https://github.com/web-infra-dev/rspress/blob/150f770aaa3a02407af3ac3e25f0df36ddc4ac59/packages/shared/src/runtime-utils/index.ts#L24 needs to be refactored.

Reproduce link

rspress/e2e/title-suffix

Reproduce Steps

clone the rspress repo

  1. pnpm install
  2. cd ./e2e/title-suffix
  3. run DEBUG=rsbuild rspress build
SoonIter commented 2 weeks ago

I have an idea to refactor rspress to use only one rsbuild instance to solve this issue and get the better performance (maybe).

https://github.com/web-infra-dev/rspress/blob/150f770aaa3a02407af3ac3e25f0df36ddc4ac59/packages/core/src/node/build.ts#L42-L59

just like

// rsbuild.config.ts
export default {
  source: {
    entry({ target }) {
      if (target === 'web') {
        return {
          index: './src/index.client.js',
        };
      }
      if (target === 'node') {
        return {
          index: './src/index.server.js',
        };
      }
    },
  },
  tools: {
         rspack(options, { env }) {
            if (env === 'node') {
                options.output.filename = 'main.cjs';
            }
          },
  },
  output: {
    targets: ['web', 'node'],
   }
};