58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
import * as esbuild from "esbuild";
|
|
import * as path from "path";
|
|
import * as fs from "fs";
|
|
import * as url from "url";
|
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
|
|
const context = await esbuild.context({
|
|
entryPoints: [
|
|
"*.ts",
|
|
"icons/**/*",
|
|
],
|
|
outdir: "./dist",
|
|
bundle: true,
|
|
platform: "node",
|
|
target: "esnext",
|
|
format: "esm",
|
|
loader: {
|
|
".png": "copy",
|
|
".ico": "copy",
|
|
},
|
|
plugins: [
|
|
{
|
|
name: "copy-shoelace-assets",
|
|
setup(build) {
|
|
let hasCopied = false;
|
|
build.onStart(() => {
|
|
if (!hasCopied) {
|
|
// We only copy one time, these files shouldn't be changing often.
|
|
const shoelaceAssets = path.resolve(
|
|
__dirname,
|
|
"node_modules/@shoelace-style/shoelace/dist/assets",
|
|
);
|
|
const outputDir = path.resolve(
|
|
__dirname,
|
|
"dist/shoelace/assets",
|
|
);
|
|
|
|
fs.rmSync(outputDir, { force: true, recursive: true });
|
|
fs.cpSync(shoelaceAssets, outputDir, {
|
|
recursive: true,
|
|
});
|
|
hasCopied = true;
|
|
}
|
|
});
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
await context.rebuild();
|
|
|
|
if (process.argv.includes("--watch")) {
|
|
await context.watch();
|
|
console.log("watching for file changes...");
|
|
} else {
|
|
await context.dispose();
|
|
}
|