mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +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/multiple-html-bundle.asserts.ts
Normal file
35
tests/specs/bundle/html/multiple-html-bundle.asserts.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import "./basic-bundle.asserts.ts";
|
||||
|
||||
import { assertFileContains } from "./assert-helpers.ts";
|
||||
|
||||
assertFileContains("./dist/index.html", /src="\.\/index-[^\.]+\.js"/);
|
||||
assertFileContains(
|
||||
"./dist/multiple-html.html",
|
||||
/src="\.\/multiple-html-[^\.]+\.js"/,
|
||||
);
|
||||
|
||||
const jsFiles: string[] = [];
|
||||
Deno.readDirSync("./dist").forEach((entry) => {
|
||||
if (entry.name.endsWith(".js")) {
|
||||
jsFiles.push("./dist/" + entry.name);
|
||||
}
|
||||
});
|
||||
|
||||
if (jsFiles.length === 0) {
|
||||
throw new Error("No .js files found");
|
||||
}
|
||||
|
||||
const indexJsFile = jsFiles.find((file) => file.includes("index"));
|
||||
const multipleHtmlJsFile = jsFiles.find((file) =>
|
||||
file.includes("multiple-html")
|
||||
);
|
||||
|
||||
if (!indexJsFile || !multipleHtmlJsFile) {
|
||||
throw new Error("No index.js or multiple-html.js file found");
|
||||
}
|
||||
|
||||
assertFileContains(indexJsFile, "Hello, world!");
|
||||
assertFileContains(
|
||||
multipleHtmlJsFile,
|
||||
'document.body.insertAdjacentHTML("beforeend", "A");',
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue