forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wrangler]: Remove unused txt/html esbuild loaders, configured for bu…
…ndling Pages Functions (cloudflare#2900) Up until now, Pages handled `.txt` and `.html` file imports in Functions via esbuild's [loader](https://esbuild.github.io/api/#loader) option. With the landing of the Wasm module support in Pages Functions, `.txt` and `.html` file imports are now handled as external modules imports, and the existing esbuild `loader` configuration we have in place for such file types, is completely ignored. This commit cleans up the no longer used esbuild txt and html loaders, from both Functions and _worker.js bundling configurations. It also adds relevant tests and fixtures for these specific file type imports, that should have been part of our Wasm support PR, but unfortunately weren't. Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>
- Loading branch information
1 parent
084b2c5
commit 4eea0ce
Showing
13 changed files
with
135 additions
and
43 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
fixtures/pages-functions-wasm-app/external-modules/meaning-of-life.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
[.html]: The meaning of life is 21 | ||
</body> | ||
</html> |
1 change: 1 addition & 0 deletions
1
fixtures/pages-functions-wasm-app/external-modules/meaning-of-life.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[.txt]: The meaning of life is 21 |
7 changes: 7 additions & 0 deletions
7
fixtures/pages-functions-wasm-app/functions/meaning-of-life-html.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import html from "./../external-modules/meaning-of-life.html"; | ||
|
||
export async function onRequest() { | ||
return new Response(html, { | ||
headers: { "Content-Type": "text/html" }, | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
fixtures/pages-functions-wasm-app/functions/meaning-of-life-text.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import text from "./../external-modules/meaning-of-life.txt"; | ||
|
||
export async function onRequest() { | ||
return new Response(text, { | ||
headers: { "Content-Type": "text/plain" }, | ||
}); | ||
} |
4 changes: 2 additions & 2 deletions
4
...ons-wasm-app/functions/meaning-of-life.js → ...asm-app/functions/meaning-of-life-wasm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import add from "../wasm/add.wasm"; | ||
import add from "../external-modules/add.wasm"; | ||
|
||
export async function onRequest() { | ||
const addModule = await WebAssembly.instantiate(add); | ||
return new Response( | ||
`Hello WASM World! The meaning of life is ${addModule.exports.add(20, 1)}` | ||
`[.wasm]: The meaning of life is ${addModule.exports.add(20, 1)}` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
fixtures/pages-workerjs-wasm-app/external-modules/meaning-of-life.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
[.html]: The meaning of life is 21 | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import multiply from "./../wasm/multiply.wasm"; | ||
import html from "./../external-modules/meaning-of-life.html"; | ||
|
||
export default { | ||
async fetch(request, env) { | ||
const url = new URL(request.url); | ||
const multiplyModule = await WebAssembly.instantiate(multiply); | ||
|
||
if (url.pathname === "/meaning-of-life") { | ||
if (url.pathname === "/meaning-of-life-wasm") { | ||
return new Response( | ||
`Hello _worker.js WASM World! The meaning of life is ${multiplyModule.exports.multiply( | ||
`[.wasm]: The meaning of life is ${multiplyModule.exports.multiply( | ||
7, | ||
3 | ||
)}` | ||
); | ||
} | ||
|
||
if (url.pathname === "/meaning-of-life-html") { | ||
return new Response(html, { | ||
headers: { | ||
"Content-Type": "text/html", | ||
}, | ||
}); | ||
} | ||
|
||
return env.ASSETS.fetch(request); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters