mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 23:24:37 +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
|
@ -0,0 +1,38 @@
|
|||
import { assertFileContains } from "./assert-helpers.ts";
|
||||
|
||||
assertFileContains("./dist/index.html", /src="\.\/index-[^\.]+\.js"/);
|
||||
assertFileContains("./dist/sub/index.html", /src="\.\/index-[^\.]+\.js"/);
|
||||
|
||||
function walk(dir: string, fn: (entry: string) => void) {
|
||||
Deno.readDirSync(dir).forEach((entry) => {
|
||||
if (entry.isDirectory) {
|
||||
walk(dir + "/" + entry.name, fn);
|
||||
} else {
|
||||
fn(dir + "/" + entry.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const jsFiles: string[] = [];
|
||||
walk("./dist", (entry) => {
|
||||
if (entry.endsWith(".js")) {
|
||||
jsFiles.push(entry);
|
||||
}
|
||||
});
|
||||
|
||||
if (jsFiles.length === 0) {
|
||||
throw new Error("No .js files found");
|
||||
}
|
||||
|
||||
const subJsFile = jsFiles.find((file) => file.includes("sub"));
|
||||
|
||||
const indexJsFile = jsFiles.find((file) =>
|
||||
file.includes("index") && !file.includes("sub")
|
||||
);
|
||||
|
||||
if (!indexJsFile || !subJsFile) {
|
||||
throw new Error("No index.js or sub/index.js file found");
|
||||
}
|
||||
|
||||
assertFileContains(indexJsFile, "Hello, world!");
|
||||
assertFileContains(subJsFile, "Hello, world from sub!");
|
Loading…
Add table
Add a link
Reference in a new issue