Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: prebundle rspack config file by rspack itself for better config extensions support #2237

Closed
fi3ework opened this issue Mar 14, 2023 · 8 comments
Labels
feat New feature or request on hold

Comments

@fi3ework
Copy link
Member

What problem does this feature solve?

Support multiple config file extensions, such as mjs ts cjs mts cts, especially ts for better intellisense and type check.

What does the proposed API of configuration look like?

Utilize rspack itself to pre-bundle the config file. The bundling should have the following features:

  1. A default unmodifiable sane nodejs lib config
  2. Externalize dependencies in node_modules
  3. Support both ESM and CJS output
  4. Hijacking require.extensions to load CJS and use temp file (before --loader landed) for ESM.
@fi3ework fi3ework added the feat New feature or request label Mar 14, 2023
@wernerbihl
Copy link

I'm particularly interested in support for .cjs config because all my projects have "type": "module" in package.json. But when changing the sample provided "rspack.config.js" (with no requires or imports) to "rspack.config.cjs", then I get the following:

TypeError: Cannot read properties of undefined (reading 'import') at getNormalizedEntryStatic (/var/www/rspack-project/node_modules/@rspack/core/src/config/normalization.ts:202:33) at getNormalizedRspackOptions (/var/www/rspack-project/node_modules/@rspack/core/src/config/normalization.ts:32:7) at createCompiler (/var/www/rspack-project/node_modules/@rspack/core/src/rspack.ts:55:44) at create (/var/www/rspack-project/node_modules/@rspack/core/src/rspack.ts:141:20) at rspack (/var/www/rspack-project/node_modules/@rspack/core/src/rspack.ts:165:31) at RspackCLI.createCompiler (/var/www/rspack-project/node_modules/@rspack/cli/src/rspack-cli.ts:49:26) at Object.handler (/var/www/rspack-project/node_modules/@rspack/cli/src/commands/build.ts:94:22)

@hardfist
Copy link
Contributor

hardfist commented May 6, 2023

@wernerbihl .cjs is supported

@hardfist
Copy link
Contributor

hardfist commented May 6, 2023

@fi3ework prebundle may meet lots of issue like web-infra-dev/modern.js#3338 when used in monorepo, if we bundle code in other package it will cause the bundled config can't find the its dependencies, so we think transformer is less prone

@fi3ework
Copy link
Member Author

fi3ework commented May 6, 2023

Prebundling could externalize bare imports, which would skip libraries in a monorepo, but still will meet type: module/commonjs issues.

@hardfist
Copy link
Contributor

hardfist commented May 6, 2023

if config a in packageA use source b in packageB which has dependency c, when we do prebundle it will cause b is bundled in bundled_a file which is in packageB, then we do resolve dependency in bundle_a it will resolve failed because lies in packageB's node_modules other than packageA's node_modules

packageA
  config_a 
packageB
  b -> require('c')
  node_modules/c

when bundled config_a it will becomes

packageA
  config_a
  bundled_config_a -> require('c')
packageB
  b
  node_modules/c

then require('c') will failed because packageA doesn't have c in node_modules

@fi3ework
Copy link
Member Author

fi3ework commented May 6, 2023

Yes, it will. I was trying to say that making bare import externalized will keep resolving 'c' from B, which is how Vite behaves now. But that will not work for loading ts in other monorepo package. Using a transformer could be a more powerful solution.

@hardfist
Copy link
Contributor

hardfist commented May 6, 2023

Yes, it will. I was trying to say that making bare import externalized will keep resolving 'c' from B, which is how Vite behaves now. But that will not work for loading ts in other monorepo package. Using a transformer could be a more powerful solution.

then we will stick to transformer solution for now and may use rspack itself to transform config one day.

@hardfist
Copy link
Contributor

hardfist commented May 6, 2023

closed as not planned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request on hold
Projects
None yet
Development

No branches or pull requests

3 participants