lgarron / barely-a-dev-server

A teeny-tiny alternative to bundlers that does just what you need (and nothing more), using `esbuild`.
Other
6 stars 0 forks source link

Leave the file serving to `esbuild`? #2

Open lgarron opened 2 years ago

lgarron commented 2 years ago

For example: npx esbuild --serve --format=esm --bundle --splitting --servedir=src/ src/**/*.ts

--servedir needs to be swapped out for building to dist, though, and replaced by manual copying.

lgarron commented 8 months ago

I think this is still not possible:

npx esbuild --serve --format=esm --bundle --splitting --servedir=test/root/ test/root/**/*.ts
✘ [ERROR] Must use "outdir" when code splitting is enabled

1 error
npx esbuild --serve --format=esm --bundle --splitting --outdir=dist/dev/test/root --servedir=test/root/ test/root/**/*.ts
✘ [ERROR] Output directory "dist/dev/test/root" must be contained in serve directory "test/root"

1 error
lgarron commented 8 months ago

Aha!

This doesn't seem to write out files:

npx esbuild --serve --format=esm --bundle --splitting --outdir=test/root --watch --servedir=test/root/ test/root/**/*.ts
lgarron commented 8 months ago

This doesn't seem to write out files:

Unfortunately, this does seem to write files to the source dir:

  const esbuildOptions = {
    target: "es2020",
    logLevel: "info",
    minify: !options.dev,
    sourcemap: true,
    format: "esm",
    bundle: true,
    splitting: true,
    ...options.esbuildOptions,
    entryPoints: [join(options.entryRoot, "**", "*.ts")],
  };
  if (options.dev) {
    esbuildOptions.outdir = options.entryRoot;
    currentBuildContext = await esbuild.context(esbuildOptions);
    await Promise.all([
      // currentBuildContext.watch(),
      currentBuildContext.serve({
        servedir: options.entryRoot,
      }),
    ]);
  } else {
    esbuildOptions.outdir = options.outDir;
    await esbuild.build(esbuildOptions);
  }

https://github.com/evanw/esbuild/issues/3013 has more info.