buildUtils.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: ["index.ts"],
  11. entryNames: "[name]",
  12. assetNames: "[dir]/[name]",
  13. alias: {
  14. "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
  15. "@excalidraw/utils": path.resolve(__dirname, "../packages/utils"),
  16. "@excalidraw/math": path.resolve(__dirname, "../packages/math"),
  17. },
  18. });
  19. function buildDev(config) {
  20. return build({
  21. ...config,
  22. sourcemap: true,
  23. plugins: [sassPlugin(), woff2ServerPlugin()],
  24. define: {
  25. "import.meta.env": JSON.stringify({ DEV: true }),
  26. },
  27. });
  28. }
  29. function buildProd(config) {
  30. return build({
  31. ...config,
  32. minify: true,
  33. plugins: [
  34. sassPlugin(),
  35. woff2ServerPlugin({
  36. outdir: `${config.outdir}/assets`,
  37. }),
  38. ],
  39. define: {
  40. "import.meta.env": JSON.stringify({ PROD: true }),
  41. },
  42. });
  43. }
  44. const createESMRawBuild = async () => {
  45. // development unminified build with source maps
  46. buildDev(getConfig("dist/dev"));
  47. // production minified build without sourcemaps
  48. buildProd(getConfig("dist/prod"));
  49. };
  50. (async () => {
  51. await createESMRawBuild();
  52. })();