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]: Build orchestration API #2916

Open
jacob-ebey opened this issue Jul 13, 2024 · 4 comments
Open

[Feature]: Build orchestration API #2916

jacob-ebey opened this issue Jul 13, 2024 · 4 comments

Comments

@jacob-ebey
Copy link

jacob-ebey commented Jul 13, 2024

What problem does this feature solve?

In some situations (such as RSC) we need to be able to orchestrate the order and number of times an environments build is ran. A simple example of this goes something like this:

  1. Build server, discover "use client"
  2. Build client with discovered client modules, discover "use server"
  3. Re-build server with discovered server modules, discover new "use client"
  4. etc...

What does the proposed API look like?

Vite's new environments API comes with a builder.buildApp API and I propose something very similar for use here:

export default defineConfig({
  builder: {
    buildApp: async (builder) => {
      await builder.build(builder.environments.browser);
      await builder.build(builder.environments.server);
    },
  },
});

This would allow us to write logic such as:

export default defineConfig({
  builder: {
    buildApp: async (builder) => {
      do {
        checkpointDiscoveredModules();
        await builder.build(builder.environments.server);
        await Promise.all([
          builder.build(builder.environments.browser),
          builder.build(builder.environments.ssr),
        ]);
      } while (discoveredNewModules());
    },
  },
});
@chenjiahan
Copy link
Member

I totally agree, Rsbuild needs to provide similar capabilities.

First we need to clarify what is the main difference between the proposed builder.build API and Rsbuild's JavaScript API (rsbuild.build()). And I wonder if it should be implemented via the JavaScript API rather than the Rsbuild configuration.

@jacob-ebey
Copy link
Author

jacob-ebey commented Jul 13, 2024

I'm beyond tired of having to maintain "build CLIs". Vite's approach is correct here. It allows a plugin / framework to define the order / interplay between builds completely within their plugin. No more xyz build, xyz dev. It's just bundler dev builder build --app to specify we want the output of the environments that make up the cohesive application. For cohesion today everywhere except for Vite6 MUST be done via a custom maintained CLI / tool that uses the specific bundler JS APIs.

@jacob-ebey
Copy link
Author

I'd recommend implementing it via the JS API and exposing that to plugins / config via the above convenience layer so it can be used "internally" instead of "externally".

@chenjiahan
Copy link
Member

Ok, so our goal is to allow Rsbuild plugin to orchestrate the build process, instead of calling JS API via a custom CLI. This should be useful for frameworks like Remix.

We will look at the design of Vite 6 next week and consider how Rsbuild can achieve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants