feat(website): add build script for frontend dependencies
This commit is contained in:
parent
7e8dc4ec5a
commit
698294c74e
10 changed files with 181 additions and 16 deletions
66
packages/website/_scripts/build.ts
Normal file
66
packages/website/_scripts/build.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import type { BuildConfig, BunPlugin, PluginBuilder } from "bun";
|
||||
import type { FileImporter } from "sass";
|
||||
|
||||
const outdir = "./static";
|
||||
|
||||
const nodeModuleImporter: FileImporter<"async"> = {
|
||||
findFileUrl(url) {
|
||||
if (url.startsWith("@")) {
|
||||
return new URL(import.meta.resolve(url));
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
const sassPlugin: BunPlugin = {
|
||||
name: "Sass Loader",
|
||||
async setup(build: PluginBuilder) {
|
||||
const sass = await import("sass");
|
||||
build.onLoad({ filter: /\.scss$/ }, async ({ path }) => {
|
||||
// read and compile it with the sass compiler
|
||||
const result = await sass.compileAsync(path, {
|
||||
importers: [nodeModuleImporter],
|
||||
});
|
||||
|
||||
return {
|
||||
loader: "css",
|
||||
contents: result.css,
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const assets: BuildConfig[] = [
|
||||
{
|
||||
entrypoints: ["./sass/style.scss"],
|
||||
outdir: `${outdir}/css`,
|
||||
naming: "[name].css",
|
||||
plugins: [sassPlugin],
|
||||
minify: true,
|
||||
|
||||
// On by default in Bun v1.2+
|
||||
html: true,
|
||||
experimentalCss: true,
|
||||
},
|
||||
|
||||
{
|
||||
entrypoints: ["./js/index.ts"],
|
||||
outdir: `${outdir}/js`,
|
||||
target: "browser",
|
||||
splitting: true,
|
||||
minify: true,
|
||||
},
|
||||
];
|
||||
|
||||
await Promise.all(
|
||||
assets.map(async (item) => {
|
||||
const result = await Bun.build(item);
|
||||
|
||||
if (!result.success) {
|
||||
throw new AggregateError(result.logs, "Build failed");
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
console.log(`${Bun.color("#a6da95", "ansi")}Assets succesfully build!\x1b[0m`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue