From 72ece7c00b091011617fccf719df7f602cf4f7c7 Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Sun, 15 Mar 2026 16:19:36 -0400 Subject: refactor: scripts/ --- scripts/buildUtils.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 scripts/buildUtils.js (limited to 'scripts/buildUtils.js') diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js new file mode 100644 index 0000000..65b9473 --- /dev/null +++ b/scripts/buildUtils.js @@ -0,0 +1,58 @@ +const path = require("path"); +const { build } = require("esbuild"); +const { sassPlugin } = require("esbuild-sass-plugin"); +const { woff2ServerPlugin } = require("./woff2/woff2-esbuild-plugins"); + +// contains all dependencies bundled inside +const getConfig = (outdir) => ({ + outdir, + bundle: true, + format: "esm", + entryPoints: ["index.ts"], + entryNames: "[name]", + assetNames: "[dir]/[name]", + alias: { + "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"), + "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"), + "@excalidraw/math": path.resolve(__dirname, "../packages/math"), + }, +}); + +function buildDev(config) { + return build({ + ...config, + sourcemap: true, + plugins: [sassPlugin(), woff2ServerPlugin()], + define: { + "import.meta.env": JSON.stringify({ DEV: true }), + }, + }); +} + +function buildProd(config) { + return build({ + ...config, + minify: true, + plugins: [ + sassPlugin(), + woff2ServerPlugin({ + outdir: `${config.outdir}/assets`, + }), + ], + define: { + "import.meta.env": JSON.stringify({ PROD: true }), + }, + }); +} + +const createESMRawBuild = async () => { + // development unminified build with source maps + buildDev(getConfig("dist/dev")); + + // production minified build without sourcemaps + buildProd(getConfig("dist/prod")); +}; + +(async () => { + await createESMRawBuild(); +})(); -- cgit v1.2.3