buildBase.js 1.3 KB

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