Skip to content

Commit

Permalink
feat: output esm build & exports
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Feb 14, 2022
1 parent fb5dad7 commit 8f990f8
Show file tree
Hide file tree
Showing 4 changed files with 1,237 additions and 1,177 deletions.
35 changes: 31 additions & 4 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import path from "path";
import glob from "fast-glob";
import { build } from "esbuild";
import { build, BuildOptions } from "esbuild";

(async () => {
const entryPoints = [];
Expand All @@ -21,15 +21,42 @@ import { build } from "esbuild";
}
}

await build({
const opts: BuildOptions = {
outdir,
entryPoints,
format: "cjs",
outbase: srcdir,
platform: "node",
target: ["es2019"],
define: {
"process.env.NODE_ENV": "'production'",
},
});
};

await Promise.all([
build({
...opts,
format: "cjs",
}),
build({
...opts,
format: "esm",
bundle: true,
splitting: true,
outExtension: { ".js": ".mjs" },
plugins: [
{
name: "external-modules",
setup(build) {
build.onResolve(
{ filter: /^[^./]|^\.[^./]|^\.\.[^/]/ },
({ path }) => ({
path,
external: true,
})
);
},
},
],
}),
]);
})();
Loading

0 comments on commit 8f990f8

Please sign in to comment.