buildExample.mjs 807 B

1234567891011121314151617181920212223242526272829303132333435
  1. import * as esbuild from "esbuild";
  2. import { sassPlugin } from "esbuild-sass-plugin";
  3. import { execSync } from "child_process";
  4. const createDevBuild = async () => {
  5. return await esbuild.build({
  6. entryPoints: ["example/index.tsx"],
  7. outfile: "example/public/bundle.js",
  8. define: {
  9. "import.meta.env": "{}",
  10. },
  11. bundle: true,
  12. format: "esm",
  13. plugins: [sassPlugin()],
  14. loader: {
  15. ".woff2": "dataurl",
  16. ".html": "copy",
  17. },
  18. });
  19. };
  20. const startServer = async (ctx) => {
  21. await ctx.serve({
  22. servedir: "example/public",
  23. port: 5001,
  24. });
  25. };
  26. execSync(
  27. `rm -rf example/public/dist && yarn build:esm && cp -r dist example/public`,
  28. );
  29. const ctx = await createDevBuild();
  30. // await startServer(ctx);
  31. // console.info("Hosted at port http://localhost:5001!!");