fix: build binary of core
All checks were successful
Publish package / build_and_publish (push) Successful in 26s
All checks were successful
Publish package / build_and_publish (push) Successful in 26s
This commit is contained in:
parent
93da2ccbad
commit
e80fa615dc
2 changed files with 104 additions and 2 deletions
99
packages/core/build.ts
Normal file
99
packages/core/build.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
#!/usr/bin/env bun
|
||||||
|
|
||||||
|
import type { BuildConfig, BunPlugin, PluginBuilder } from "bun";
|
||||||
|
import { parseArgs } from "node:util";
|
||||||
|
import type { FileImporter } from "sass";
|
||||||
|
|
||||||
|
const { values, positionals } = parseArgs({
|
||||||
|
args: Bun.argv,
|
||||||
|
options: {
|
||||||
|
production: {
|
||||||
|
type: "boolean",
|
||||||
|
short: "p",
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
type: "string",
|
||||||
|
short: "f",
|
||||||
|
default: "all",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
strict: true,
|
||||||
|
allowPositionals: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const outdir = positionals.at(2);
|
||||||
|
|
||||||
|
if (!outdir) {
|
||||||
|
throw new Error("No outdir provided!");
|
||||||
|
}
|
||||||
|
|
||||||
|
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[] = [];
|
||||||
|
|
||||||
|
const filter = values.filter ?? "all";
|
||||||
|
|
||||||
|
if (["all", "sass"].includes(filter)) {
|
||||||
|
assets.push({
|
||||||
|
entrypoints: ["./src/style.scss"],
|
||||||
|
outdir: `${outdir}/css`,
|
||||||
|
naming: "[name].css",
|
||||||
|
plugins: [sassPlugin],
|
||||||
|
minify: values.production,
|
||||||
|
|
||||||
|
// On by default in Bun v1.2+
|
||||||
|
html: true,
|
||||||
|
experimentalCss: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (["all", "js", "ts"].includes(filter)) {
|
||||||
|
// assets.push({
|
||||||
|
// entrypoints: ["./js/index.ts"],
|
||||||
|
// outdir: `${outdir}/js`,
|
||||||
|
// target: "browser",
|
||||||
|
// splitting: values.production,
|
||||||
|
// minify: values.production,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
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;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`${Bun.color("#a6da95", "ansi")}Assets succesfully build!\x1b[0m`);
|
||||||
|
|
@ -6,9 +6,12 @@
|
||||||
".": "./src/style.scss",
|
".": "./src/style.scss",
|
||||||
"./mixins": "./src/_mixins.scss"
|
"./mixins": "./src/_mixins.scss"
|
||||||
},
|
},
|
||||||
|
"bin": {
|
||||||
|
"@mini-strap/core": "build.ts"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "bun sass --style compressed src/style.scss",
|
"build": "bun sass --style compressed src/style.scss dist/style.css",
|
||||||
"ci:publish": "bun run build dist/style.css && bun publish --production --frozen-lockfile --silent"
|
"ci:publish": "bun run build && bun publish --production --frozen-lockfile --silent"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue