web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.87k stars 571 forks source link

[Feature]: There are some missing APIs for frameworks support React Server Component #8469

Open yimingjfe opened 20 hours ago

yimingjfe commented 20 hours ago

What problem does this feature solve?

In Modern.js, we want to support RSC building base on Rspack. When using webpack, the solution can work normally, but with Rspack, there are some APIs that are not exported now, so it's difficult to support RSC in the Modern.js repository.

The following APIs are currently used for support RSC, but are not seen exported in Rspack:

Server-side building:

  1. Add modules to the compilation

    • compilation.addInclude
    • Avoiding tree-shaking of the modules
    • webpack.util.runtime.getEntryRuntime
    • compilation.moduleGraph.getExportsInfo
    • exportsInfo.setUsedInUnknownWay
    • compilation.hooks.needAdditionalPass
  2. Add custom dependencies

    • compilation.dependencyFactories
    • compilation.dependencyTemplates
    • module.addDependency
    • NullDependency
  3. Get ModuleId

    • compilation.hooks.afterOptimizeModuleIds
    • chunkGraph.getModuleId

Client-side building:

  1. Add client reference chunks

    • AsyncDependenciesBlock
    • block.addDependency
    • Module
    • module.blocks
    • module.addBlock
  2. Get moduleInfo

    • module.nameForCondition
    • chunkGraph.getModuleId
    • chunkGraph.getModuleChunksIterable
    • moduleGraph.getOutgoingConnections

Here there are some APIs that may have alternatives , and some are difficult to have real alternatives.

I want to discuss what the recommended solution is from the perspective of Rspack, such as the addDependency API, in the webpack ecosystem, there are many webpack plugins that depend on it.

What does the proposed API of configuration look like?

It is best to be consistent with webpack.

GiveMe-A-Name commented 17 hours ago

The compilation.entries.entries is exists. You can use it directly. Then webpack.util.runtime.getEntryRuntime is not exported in webpack also, maybe you need implement by yourself. And other api or attributes will be implemented in the future.

GiveMe-A-Name commented 17 hours ago

Tasks

SyMind commented 16 hours ago

I am supporting module graph api here: https://github.com/web-infra-dev/rspack/pull/8470

yimingjfe commented 16 hours ago

The compilation.entries.entries is exists. You can use it directly. Then webpack.util.runtime.getEntryRuntime is not exported in webpack also, maybe you need implement by youself. And other api or attributes we will add in the future.

Yeah, you are right, compilation.entries.entries already exists, I'll update the description.

For getEntryRuntime, in webpack, it is possible to get it by compiler.webpack.util.runtime.getEntryRuntime.

inottn commented 3 hours ago

I would like to know where the hooks listed above are used in the RSC build. Do we have corresponding links to check?