buildMath.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const path = require("path");
  2. const { build } = require("esbuild");
  3. const { sassPlugin } = require("esbuild-sass-plugin");
  4. // contains all dependencies bundled inside
  5. const getConfig = (outdir) => ({
  6. outdir,
  7. bundle: true,
  8. format: "esm",
  9. entryPoints: ["index.ts"],
  10. entryNames: "[name]",
  11. assetNames: "[dir]/[name]",
  12. alias: {
  13. "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
  14. "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"),
  15. "@excalidraw/math": path.resolve(__dirname, "../packages/math"),
  16. },
  17. });
  18. function buildDev(config) {
  19. return build({
  20. ...config,
  21. plugins: [sassPlugin()],
  22. sourcemap: true,
  23. define: {
  24. "import.meta.env": JSON.stringify({ DEV: true }),
  25. },
  26. });
  27. }
  28. function buildProd(config) {
  29. return build({
  30. ...config,
  31. plugins: [sassPlugin()],
  32. minify: true,
  33. define: {
  34. "import.meta.env": JSON.stringify({ PROD: true }),
  35. },
  36. });
  37. }
  38. const createESMRawBuild = async () => {
  39. // development unminified build with source maps
  40. buildDev(getConfig("dist/dev"));
  41. // production minified build without sourcemaps
  42. buildProd(getConfig("dist/prod"));
  43. };
  44. (async () => {
  45. await createESMRawBuild();
  46. })();