Skip to content

feat: Allow project-owned vite plugin dep #537

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

Merged
merged 10 commits into from
Jun 23, 2025
Merged

Conversation

justinvdm
Copy link
Collaborator

@justinvdm justinvdm commented Jun 23, 2025

Problem

Currently, RedwoodSDK includes @cloudflare/vite-plugin itself in vite configuration. This make it difficult control which version of this plugin you are on or configure it a specific way.

⚠️ Breaking change

note: This is only a breaking change if you have @cloudflare/vite-plugin as a dependency in your own project.

The new behaviour:

  • If the project has @cloudflare/vite-plugin as its own dependency, RedwoodSDK will not instantiate @cloudflare/vite-plugin itself in vite configuration
  • If the project does not have @cloudflare/vite-plugin as its own dependency (most likely case), RedwoodSDK will work as normal: will instantiate @cloudflare/vite-plugin itself in vite configuration

Migrating

The recommended approach is now to include @cloudflare/vite-plugin as a dependency in your project's package.json:

{
  ...
  "devDependencies": {
    ...
    "@cloudflare/vite-plugin": "1.7.4",
    "@cloudflare/workers-types": "^4.20250407.0",
    "wrangler": "^4.20.5"
  },
}

... then add the plugin to your vite.config.ts:

import { defineConfig } from "vite";
import { redwood } from "rwsdk/vite";
import { cloudflare } from "@cloudflare/vite-plugin";

export default defineConfig({
  plugins: [
    cloudflare({
      viteEnvironment: { name: "worker" },
    }),
    redwood(),
  ],
});

plugins: [
cloudflare({
viteEnvironment: { name: "worker" },
}),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterp note this - its a bit unfortunate, I don't think there's much we can do about it. Looks like CF use worker name in wrangler config as default for environment name, but that won't work for us since we need to know the name ahead of time for our configuration.

I mean, we could technically dynamically configure stuff to make that possible, but that feels like a lot, not sure if worth it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine!

@peterp
Copy link
Member

peterp commented Jun 23, 2025

I approve these changes!

@justinvdm justinvdm merged commit c47a152 into main Jun 23, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants