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/buildPackage.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 scripts/buildPackage.js (limited to 'scripts/buildPackage.js') diff --git a/scripts/buildPackage.js b/scripts/buildPackage.js new file mode 100644 index 0000000..653af50 --- /dev/null +++ b/scripts/buildPackage.js @@ -0,0 +1,79 @@ +const path = require("path"); +const { build } = require("esbuild"); +const { sassPlugin } = require("esbuild-sass-plugin"); +const { parseEnvVariables } = require("../packages/excalidraw/env.cjs"); + +const ENV_VARS = { + development: { + ...parseEnvVariables(`${__dirname}/../.env.development`), + DEV: true, + }, + production: { + ...parseEnvVariables(`${__dirname}/../.env.production`), + PROD: true, + }, +}; + +// excludes all external dependencies and bundles only the source code +const getConfig = (outdir) => ({ + outdir, + bundle: true, + splitting: true, + format: "esm", + packages: "external", + plugins: [sassPlugin()], + target: "es2020", + assetNames: "[dir]/[name]", + chunkNames: "[dir]/[name]-[hash]", + alias: { + "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"), + "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"), + "@excalidraw/math": path.resolve(__dirname, "../packages/math"), + }, + loader: { + ".woff2": "file", + }, +}); + +function buildDev(config) { + return build({ + ...config, + sourcemap: true, + define: { + "import.meta.env": JSON.stringify(ENV_VARS.development), + }, + }); +} + +function buildProd(config) { + return build({ + ...config, + minify: true, + define: { + "import.meta.env": JSON.stringify(ENV_VARS.production), + }, + }); +} + +const createESMRawBuild = async () => { + const chunksConfig = { + entryPoints: ["index.tsx", "**/*.chunk.ts"], + entryNames: "[name]", + }; + + // development unminified build with source maps + await buildDev({ + ...getConfig("dist/dev"), + ...chunksConfig, + }); + + // production minified buld without sourcemaps + await buildProd({ + ...getConfig("dist/prod"), + ...chunksConfig, + }); +}; + +(async () => { + await createESMRawBuild(); +})(); -- cgit v1.2.3