Skip to content

Commit 7688e32

Browse files
committed
build: Change to use esbuild.
- Drop esm as cosmiconfig doesn't support it anyway.
1 parent 90a5683 commit 7688e32

File tree

6 files changed

+1274
-262
lines changed

6 files changed

+1274
-262
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"ignorePatterns": [
88
"lib/__fixtures__/**/*.ts",
9+
"esbuild.config.mjs",
910
"jest.config.ts",
1011
"coverage",
1112
"dist"

esbuild.config.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import chalk from "chalk";
2+
import { analyzeMetafile, build } from "esbuild";
3+
import { readFile } from "fs/promises";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const nodeTargets = ["node14", "node16", "node18"];
8+
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
const packageJsonPath = path.resolve(__dirname, "package.json");
11+
12+
async function getExternals() {
13+
const packageJson = JSON.parse(await readFile(packageJsonPath));
14+
15+
return Object.keys(packageJson.peerDependencies);
16+
}
17+
18+
(async () => {
19+
try {
20+
const startTime = Date.now();
21+
console.info(
22+
chalk.bold(
23+
`🚀 ${chalk.blueBright("cosmiconfig-typescript-loader")} Build\n`
24+
)
25+
);
26+
27+
const externalDeps = await getExternals();
28+
29+
const result = await build({
30+
entryPoints: ["./lib/index.ts"],
31+
outfile: "dist/cjs/index.js",
32+
metafile: true,
33+
bundle: true,
34+
format: "cjs",
35+
external: externalDeps,
36+
platform: "node",
37+
target: nodeTargets,
38+
treeShaking: true,
39+
});
40+
41+
const analysis = await analyzeMetafile(result.metafile);
42+
console.info(`📝 Bundle Analysis:${analysis}`);
43+
44+
console.info(
45+
`${chalk.bold.green("✔ Bundled successfully!")} (${
46+
Date.now() - startTime
47+
}ms)`
48+
);
49+
} catch (error) {
50+
console.error(`🧨 ${chalk.red.bold("Failed:")} ${error.message}`);
51+
console.debug(`📚 ${chalk.blueBright.bold("Stack:")} ${error.stack}`);
52+
process.exit(1);
53+
}
54+
})();

0 commit comments

Comments
 (0)