update build
This commit is contained in:
parent
697a7ac658
commit
a0039ef150
1 changed files with 50 additions and 490 deletions
78
build.ts
78
build.ts
|
|
@ -25,45 +25,45 @@ async function buildJs(
|
|||
}
|
||||
|
||||
await Promise.all([
|
||||
buildJs("src/index.ts", { outdir: "dist/src" }),
|
||||
buildJs("src/react/useApp.tsx", { outdir: "dist/src/react" }),
|
||||
buildJs("examples/example-ui-react.tsx", { outdir: "dist/examples" }),
|
||||
buildJs("examples/example-ui.ts", { outdir: "dist/examples" }),
|
||||
buildJs("examples/example-server.ts", {
|
||||
target: "node",
|
||||
outdir: "dist/examples",
|
||||
}),
|
||||
buildJs("src/app.ts"),
|
||||
buildJs("src/react/index.tsx", { outdir: "dist/react" }),
|
||||
// buildJs("examples/example-ui-react.tsx", { outdir: "dist/examples" }),
|
||||
// buildJs("examples/example-ui.ts", { outdir: "dist/examples" }),
|
||||
// buildJs("examples/example-server.ts", {
|
||||
// target: "node",
|
||||
// outdir: "dist/examples",
|
||||
// }),
|
||||
]);
|
||||
|
||||
async function inlineHtml(htmlFilePath: string, outputFilePath: string) {
|
||||
let html = await readFile(htmlFilePath, "utf-8");
|
||||
// Find all src sources, then fetch them, then replace them
|
||||
const files = html.matchAll(
|
||||
/<script src="((?:\.\/)?dist\/.*?\.js)"><\/script>/g,
|
||||
);
|
||||
const fileContent = Object.fromEntries(
|
||||
await Promise.all(
|
||||
Array.from(files, async ([, filename]) => {
|
||||
const scriptContent = await readFile(filename, "utf-8");
|
||||
return [filename, scriptContent];
|
||||
}),
|
||||
),
|
||||
);
|
||||
html = html.replace(
|
||||
/<script src="((?:\.\/)?dist\/.*?\.js)"><\/script>/g,
|
||||
(_, filename) => {
|
||||
let scriptContent = fileContent[filename];
|
||||
// Escape </script> to prevent premature script tag closing
|
||||
// This is the standard way to inline scripts safely
|
||||
scriptContent = scriptContent.replace(/<\/script>/gi, "<\\/script>");
|
||||
return `<script>${scriptContent}</script>`;
|
||||
},
|
||||
);
|
||||
await writeFile(outputFilePath, html);
|
||||
}
|
||||
// async function inlineHtml(htmlFilePath: string, outputFilePath: string) {
|
||||
// let html = await readFile(htmlFilePath, "utf-8");
|
||||
// // Find all src sources, then fetch them, then replace them
|
||||
// const files = html.matchAll(
|
||||
// /<script src="((?:\.\/)?dist\/.*?\.js)"><\/script>/g,
|
||||
// );
|
||||
// const fileContent = Object.fromEntries(
|
||||
// await Promise.all(
|
||||
// Array.from(files, async ([, filename]) => {
|
||||
// const scriptContent = await readFile(filename, "utf-8");
|
||||
// return [filename, scriptContent];
|
||||
// }),
|
||||
// ),
|
||||
// );
|
||||
// html = html.replace(
|
||||
// /<script src="((?:\.\/)?dist\/.*?\.js)"><\/script>/g,
|
||||
// (_, filename) => {
|
||||
// let scriptContent = fileContent[filename];
|
||||
// // Escape </script> to prevent premature script tag closing
|
||||
// // This is the standard way to inline scripts safely
|
||||
// scriptContent = scriptContent.replace(/<\/script>/gi, "<\\/script>");
|
||||
// return `<script>${scriptContent}</script>`;
|
||||
// },
|
||||
// );
|
||||
// await writeFile(outputFilePath, html);
|
||||
// }
|
||||
|
||||
await inlineHtml("examples/example-ui.html", "dist/examples/example-ui.html");
|
||||
await inlineHtml(
|
||||
"examples/example-ui-react.html",
|
||||
"dist/examples/example-ui-react.html",
|
||||
);
|
||||
// await inlineHtml("examples/example-ui.html", "dist/examples/example-ui.html");
|
||||
// await inlineHtml(
|
||||
// "examples/example-ui-react.html",
|
||||
// "dist/examples/example-ui-react.html",
|
||||
// );
|
||||
|
|
|
|||
Loading…
Reference in a new issue