Skip to content

Add support for using the Vite plugin without a Wrangler config file#11408

Merged
ascorbic merged 5 commits intomainfrom
mk/vite-plugin/zero-config
Nov 26, 2025
Merged

Add support for using the Vite plugin without a Wrangler config file#11408
ascorbic merged 5 commits intomainfrom
mk/vite-plugin/zero-config

Conversation

@ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Nov 25, 2025

Add support for using the Vite plugin without a wrangler.* file. If no file is present it instead generates a default config suitable for an assets-only site.

Fixes [DEVX-2351].


  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: I'll add docs in the next stage where we allow the plugin user to modify the config
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: not wrangler

@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2025

🦋 Changeset detected

Latest commit: be6406d

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@ascorbic ascorbic force-pushed the mk/vite-plugin/zero-config branch from 90c3a70 to 8934055 Compare November 25, 2025 13:15
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 25, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11408

wrangler

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

commit: be6406d

@ascorbic ascorbic force-pushed the mk/vite-plugin/zero-config branch from eb0c267 to a064893 Compare November 25, 2025 13:53
@ascorbic ascorbic marked this pull request as ready for review November 25, 2025 14:34
@ascorbic ascorbic requested a review from a team as a code owner November 25, 2025 14:34
@ascorbic ascorbic requested a review from a team November 25, 2025 14:34
Comment on lines 361 to 371
// Get worker name from package.json name or directory basename
const packageJsonPath = path.join(root, "package.json");
let workerName: string;
try {
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
const packageJson = JSON.parse(packageJsonContent) as { name?: string };
if (packageJson.name) {
workerName = unstable_toValidWorkerName(packageJson.name);
}
} catch {}
workerName ??= unstable_toValidWorkerName(path.basename(root));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should more of this logic be shared with auto-config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reckon I should move it into wrangler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, moved to wrangler and reused more of the autoconfig code. 593d36c

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Nov 26, 2025
@ascorbic ascorbic requested a review from jamesopstad November 26, 2025 11:23
);
packageJsonName = packageJson.name;
} catch {
logger.debug("No package.json found when deriving worker name");
Copy link
Contributor

@jamesopstad jamesopstad Nov 26, 2025

Choose a reason for hiding this comment

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

I think we should avoid pulling in the Wrangler logger in these exported utils. If we need debug logs, could we provide the logger as an argument? We could then pass in debuglog from

export const debuglog = util.debuglog("@cloudflare:vite-plugin");
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I"ll remove it for now. I don't think it's that important.

@ascorbic ascorbic merged commit f29e699 into main Nov 26, 2025
39 of 41 checks passed
@ascorbic ascorbic deleted the mk/vite-plugin/zero-config branch November 26, 2025 15:16
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants