buildUtils.js 1.6 KB

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