feat(website): add html components imports to build script
This commit is contained in:
parent
698294c74e
commit
e9db7de13c
3 changed files with 32 additions and 94 deletions
|
|
@ -1,6 +1,10 @@
|
|||
import type { BuildConfig, BunPlugin, PluginBuilder } from "bun";
|
||||
import { readdir, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import type { FileImporter } from "sass";
|
||||
|
||||
import { HTMLComponents } from "@mini-strap/components";
|
||||
|
||||
const outdir = "./static";
|
||||
|
||||
const nodeModuleImporter: FileImporter<"async"> = {
|
||||
|
|
@ -51,16 +55,42 @@ const assets: BuildConfig[] = [
|
|||
splitting: true,
|
||||
minify: true,
|
||||
},
|
||||
|
||||
{
|
||||
entrypoints: Object.values(HTMLComponents),
|
||||
outdir: "./templates/ext-components",
|
||||
target: "browser",
|
||||
naming: {
|
||||
// default values
|
||||
entry: "[name].[ext]",
|
||||
asset: "[name].[ext]",
|
||||
chunk: "[name]-[hash].[ext]",
|
||||
},
|
||||
// On by default in Bun v1.2+
|
||||
html: true,
|
||||
experimentalCss: true,
|
||||
},
|
||||
];
|
||||
|
||||
await Promise.all(
|
||||
const out = await Promise.all(
|
||||
assets.map(async (item) => {
|
||||
const result = await Bun.build(item);
|
||||
|
||||
if (!result.success) {
|
||||
throw new AggregateError(result.logs, "Build failed");
|
||||
}
|
||||
|
||||
return result;
|
||||
}),
|
||||
);
|
||||
|
||||
async function deleteJsFiles(folder: string) {
|
||||
const files = await readdir(folder);
|
||||
const jsFiles = files.filter((file) => file.endsWith(".js"));
|
||||
|
||||
await Promise.all(jsFiles.map((file) => rm(join(folder, file))));
|
||||
}
|
||||
|
||||
await deleteJsFiles("./templates/ext-components");
|
||||
|
||||
console.log(`${Bun.color("#a6da95", "ansi")}Assets succesfully build!\x1b[0m`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue