Skip to content

Allow Vite plugin to build server first, client last #9384

@bndkt

Description

@bndkt

Describe the solution

I'm currently building a RSC framework/Vite plugin which I want to use in combination with the Cloudflare Vite plugin. For the RSC plugin to work, it is important that the server/ssr bundle is built first, and the client bundle is built last (because client components get discovered during SSR build and then included in the client build).

The Cloudflare Vite plugin currently takes over the build process via builder.buildApp, yielding to a user config in case there is one (see

userConfig.builder?.buildApp ??
). I can provide my own builder.buildApp hook to make sure the build happens in the desired order, so this part works.

The one thing that doesn't work is that the assets config in the generated wrangler.json is only added if "hasClientBuild" is set (see

if (isEntryWorker && hasClientBuild) {
), which is only set when there was a previous build for the "client" environment.

Do you think it would be possible to change the hasClientBuild check towards something that checks if there is a client environment configured and doesn't rely on the client environment being built previously? I'm happy to create a PR for this if you'd be open to changing this.

Maybe it would even make sense to offer a "buildClientLast" option for the plugin, so that this could be set in the Cloudflare Vite plugin config? Then I wouldn't even need to take over the build process myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestvite-pluginRelating to the `@cloudflare/vite-plugin` package

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions