Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit ca799fa

Browse files
committed
Use correct script path for type = "webpack" Workers Sites projects
1 parent 8646485 commit ca799fa

File tree

12 files changed

+103
-3
lines changed

12 files changed

+103
-3
lines changed

packages/core/src/plugins/build.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,17 @@ export function _populateBuildConfig(
111111
const env = configEnv ? ` --env ${configEnv}` : "";
112112

113113
if (config.type === "webpack") {
114+
let packageDir = "";
115+
if (config.site) {
116+
// If `site` is configured, built artifacts are isolated from static-site
117+
// application code, see:
118+
// - https://github.com/cloudflare/wrangler/blob/a3bc640f13c8a4d10f3211b577037f7c32aff7ae/src/settings/toml/target.rs#L38-L48
119+
// - https://github.com/cloudflare/wrangler/blob/a3bc640f13c8a4d10f3211b577037f7c32aff7ae/src/settings/toml/site.rs#L30-L40
120+
packageDir = config.site["entry-point"] ?? "workers-site";
121+
}
122+
114123
config.build.command = `wrangler build${env}`;
115-
config.build.upload.main = path.join("worker", "script.js");
124+
config.build.upload.main = path.join(packageDir, "worker", "script.js");
116125
} else if (config.type === "rust") {
117126
// This script will be included in the root index.js bundle, but rust.mjs
118127
// will be in the plugins subdirectory
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker/

packages/core/test/fixtures/wrangler/webpack-site-custom/entry/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "webpack-site-custom-entry-worker",
3+
"version": "1.0.0",
4+
"main": "../src/index.js",
5+
"private": "true"
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addEventListener("fetch", (event) => {
2+
event.respondWith(new Response(`webpack-site-custom:${event.request.url}`));
3+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = "webpack-site-custom-entry-worker"
2+
type = "webpack"
3+
compatibility_date = "2021-12-16"
4+
5+
[site]
6+
bucket = "./public"
7+
entry-point = "./entry"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addEventListener("fetch", (event) => {
2+
event.respondWith(new Response(`webpack-site:${event.request.url}`));
3+
});

packages/core/test/fixtures/wrangler/webpack-site/workers-site/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "webpack-site-worker",
3+
"version": "1.0.0",
4+
"main": "../src/index.js",
5+
"private": "true"
6+
}

0 commit comments

Comments
 (0)