48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { build, transform } from "esbuild";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const projectRoot = path.resolve(__dirname, "..");
|
|
const { version } = JSON.parse(
|
|
await readFile(path.join(projectRoot, "package.json"), "utf8"),
|
|
);
|
|
|
|
const inlineCssTextPlugin = {
|
|
name: "inline-css-text",
|
|
setup(buildApi) {
|
|
buildApi.onLoad({ filter: /\.css$/ }, async (args) => {
|
|
const source = await readFile(args.path, "utf8");
|
|
const { code } = await transform(source, {
|
|
loader: "css",
|
|
minify: true,
|
|
});
|
|
|
|
return {
|
|
contents: `export default ${JSON.stringify(code)};`,
|
|
loader: "js",
|
|
};
|
|
});
|
|
},
|
|
};
|
|
|
|
await build({
|
|
absWorkingDir: projectRoot,
|
|
entryPoints: [path.join(projectRoot, "src", "connectTheDots.ts")],
|
|
outfile: path.join(projectRoot, "build", "connectTheDots.js"),
|
|
bundle: true,
|
|
format: "esm",
|
|
target: "es2022",
|
|
minify: true,
|
|
sourcemap: false,
|
|
charset: "utf8",
|
|
legalComments: "none",
|
|
external: ["../../scripts/app.js", "../../scripts/api.js"],
|
|
plugins: [inlineCssTextPlugin],
|
|
banner: {
|
|
js: `/* ComfyUI-ConnectTheDots Version: ${version} */\n/* https://github.com/jtreminio/ComfyUI-ConnectTheDots */`,
|
|
},
|
|
});
|