Skip to content

feat(vite-plugin): Add containers support in vite-plugin #9819

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CarmenPopoviciu
Copy link
Contributor

@CarmenPopoviciu CarmenPopoviciu commented Jul 2, 2025

Fixes #9793 & DEVX-1944


  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because:
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: containers feature does not exist in v3

Copy link

changeset-bot bot commented Jul 2, 2025

⚠️ No Changeset found

Latest commit: 33ee2d2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

pkg-pr-new bot commented Jul 2, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@9819

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@9819

miniflare

npm i https://pkg.pr.new/miniflare@9819

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@9819

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@9819

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@9819

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@9819

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@9819

wrangler

npm i https://pkg.pr.new/wrangler@9819

commit: 33ee2d2

@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/containers-in-vite branch from 6de3f9b to 1f860e2 Compare July 2, 2025 16:16
@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/containers-in-vite branch from 1f860e2 to 33ee2d2 Compare July 8, 2025 16:22
@@ -467,6 +516,13 @@ export function cloudflare(pluginConfig: PluginConfig = {}): vite.Plugin[] {
})
);
},
async closeBundle() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would really appreciate some sanity check here. According to vite docs this is the right hook where we'd want to cleanup process resources,

Screenshot 2025-07-08 at 18 25 45

but I'm new to vite so I might be overlooking smth

* with image tag set to well-known dev format, or undefined if
* containers are not enabled or not configured.
*/
async function getContainerOptions(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this aaalmost duplicates the wrangler counterpart, with the exception that containerBuildId needs to be passed into this function, as the vite-plugin does not have access to it via the config, as wrangler does

Copy link
Contributor

@emily-shen emily-shen left a comment

Choose a reason for hiding this comment

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

lgtm on an initial pass 🧡

@petebacondarwin can you have a look at this from the vite side?

// Assemble container options and build if necessary
const containerOptions = await getContainerOptions(
entryWorkerConfig,
containerBuildId as string
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe instead of casting it to a string, assert this is defined?

entryWorkerConfig,
containerBuildId as string
);
const dockerPath = unstable_getDockerPath();
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of exporting this function in wrangler, i think we can just get it off process.env. According to pete all the env var factories exist because we wanted to consolidate and warn on certain env vars. but we don't need that for this env var, so we can just get it off process.env to reduce complexity.

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

Successfully merging this pull request may close these issues.

Containers don't work with @cloudflare/vite-plugin
2 participants