Skip to content

Commit aadb49c

Browse files
authored
Make assets field optional in the Worker config when using assets (#8545)
1 parent dbbeb23 commit aadb49c

29 files changed

+362
-77
lines changed

.changeset/quiet-wombats-lead.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
Make `assets` field optional in the Worker config when using assets. At build time, assets are included if there is a client build.

packages/vite-plugin-cloudflare/playground/react-spa/src/vite-env.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/vite-plugin-cloudflare/playground/spa-with-api/src/vite-env.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from "vitest";
2+
import { page } from "../../__test-utils__";
3+
4+
test("returns the correct home page", async () => {
5+
const content = await page.textContent("h1");
6+
expect(content).toBe("Vite + TypeScript");
7+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect, test } from "vitest";
2+
import { getJsonResponse, page } from "../../../__test-utils__";
3+
4+
test("returns the correct home page", async () => {
5+
const content = await page.textContent("h1");
6+
expect(content).toBe("Vite + TypeScript");
7+
});
8+
9+
test("returns the correct response from the API", async () => {
10+
const result = await getJsonResponse("/api/");
11+
expect(result).toEqual({ name: "Cloudflare" });
12+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default {
2+
fetch(request, env) {
3+
const url = new URL(request.url);
4+
5+
if (url.pathname.startsWith("/api/")) {
6+
return Response.json({
7+
name: "Cloudflare",
8+
});
9+
}
10+
11+
return new Response(null, { status: 404 });
12+
},
13+
} satisfies ExportedHandler;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + TS</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@playground/static",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "vite build --app",
7+
"build:with-api": "vite build --app -c vite.config.with-api.ts",
8+
"check:types": "tsc --build",
9+
"dev": "vite dev",
10+
"dev:with-api": "vite dev -c vite.config.with-api.ts",
11+
"preview": "vite preview",
12+
"preview:with-api": "vite preview -c vite.config.with-api.ts"
13+
},
14+
"devDependencies": {
15+
"@cloudflare/vite-plugin": "workspace:*",
16+
"@cloudflare/workers-tsconfig": "workspace:*",
17+
"@cloudflare/workers-types": "^4.20250317.0",
18+
"typescript": "catalog:default",
19+
"vite": "catalog:vite-plugin",
20+
"wrangler": "workspace:*"
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function setupCounter(element: HTMLButtonElement) {
2+
let counter = 0;
3+
const setCounter = (count: number) => {
4+
counter = count;
5+
element.innerHTML = `count is ${counter}`;
6+
};
7+
element.addEventListener("click", () => setCounter(counter + 1));
8+
setCounter(0);
9+
}

0 commit comments

Comments
 (0)