Websites/esbuild.config.mjs
2024-05-02 22:04:43 -05:00

35 lines
955 B
JavaScript

import { sassPlugin } from "esbuild-sass-plugin";
import esbuild from "esbuild";
import chokidar from "chokidar";
/** @type import("esbuild").BuildOptions */
const options = {
entryPoints: ["./app/javascript/application.ts"],
outdir: "./app/assets/builds",
bundle: true,
allowOverwrite: true,
plugins: [
sassPlugin({
loadPaths: ["./node_modules"],
})
],
sourcemap: true,
publicPath: "assets"
};
const watch = process.argv.includes("--watch");
if(watch) {
const watcher = chokidar.watch("./app/javascript/**/*.{ts,scss}");
watcher.on("change", async () => {
console.log("👀 Change detected, rebuilding...");
await esbuild.build(options)
.then(() => console.log("⚡ Done"))
.catch(() => console.log("🚨 Failed"));
});
}
await esbuild.build(options)
.then(() => console.log("⚡ Done"))
.catch(() => console.log("🚨 Failed"));