mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 21:24:48 +00:00
feat(bundle): support html entrypoint (#29856)
For instance `deno bundle --outdir dist index.html` It will find scripts referenced in the html, bundle them, and then update the paths in index.html for the bundled assets. Right now it doesn't handle other assets (from `link` elements), but it could
This commit is contained in:
parent
41ff38ae65
commit
4e4bbf2fcc
33 changed files with 1480 additions and 74 deletions
35
tests/specs/bundle/html/imports-css-bundle.asserts.ts
Normal file
35
tests/specs/bundle/html/imports-css-bundle.asserts.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { assertFileContains } from "./assert-helpers.ts";
|
||||
|
||||
assertFileContains(
|
||||
"./dist/imports-css.html",
|
||||
/src="\.\/imports-css-[^\.]+\.js"/,
|
||||
);
|
||||
assertFileContains(
|
||||
"./dist/imports-css.html",
|
||||
/href="\.\/imports-css-[^\.]+\.css"/,
|
||||
);
|
||||
|
||||
const jsCssFiles: string[] = [];
|
||||
Deno.readDirSync("./dist").forEach((entry) => {
|
||||
if (entry.name.endsWith(".js") || entry.name.endsWith(".css")) {
|
||||
jsCssFiles.push("./dist/" + entry.name);
|
||||
}
|
||||
});
|
||||
|
||||
if (jsCssFiles.length === 0) {
|
||||
throw new Error("No .js files found");
|
||||
}
|
||||
|
||||
const importsCssJsFile = jsCssFiles.find((file) =>
|
||||
file.includes("imports-css") && file.endsWith(".js")
|
||||
);
|
||||
const cssFile = jsCssFiles.find((file) =>
|
||||
file.includes("imports-css") && file.endsWith(".css")
|
||||
);
|
||||
|
||||
if (!importsCssJsFile || !cssFile) {
|
||||
throw new Error("No imports-css.js or imports-css.css file found");
|
||||
}
|
||||
|
||||
assertFileContains(importsCssJsFile, "<h1>Hello, world!</h1>");
|
||||
assertFileContains(cssFile, "h1 {\n color: red;\n}");
|
Loading…
Add table
Add a link
Reference in a new issue