mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-08 10:01:34 +00:00
Use esbuild to generate esm bundle
This commit is contained in:
parent
e5970628e0
commit
c4f6f6794a
8 changed files with 316 additions and 30 deletions
41
esbuild.config.mjs
Normal file
41
esbuild.config.mjs
Normal file
|
@ -0,0 +1,41 @@
|
|||
import chalk from "chalk";
|
||||
import { analyzeMetafile, build } from "esbuild";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
console.info(
|
||||
chalk.bold(`🚀 ${chalk.blueBright("paths-filter")} Build\n`),
|
||||
);
|
||||
|
||||
const result = await build({
|
||||
entryPoints: ["./src/main.ts"],
|
||||
outfile: "dist/index.mjs",
|
||||
metafile: true,
|
||||
bundle: true,
|
||||
format: "esm",
|
||||
platform: "node",
|
||||
target: ["node20"],
|
||||
treeShaking: true,
|
||||
// Ensure require is properly defined: https://github.com/evanw/esbuild/issues/1921
|
||||
banner: {
|
||||
js:
|
||||
"import { createRequire } from 'module';\n" +
|
||||
"const require = createRequire(import.meta.url);",
|
||||
},
|
||||
});
|
||||
|
||||
const analysis = await analyzeMetafile(result.metafile);
|
||||
console.info(`📝 Bundle Analysis:${analysis}`);
|
||||
|
||||
console.info(
|
||||
`${chalk.bold.green("✔ Bundled successfully!")} (${
|
||||
Date.now() - startTime
|
||||
}ms)`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(`🧨 ${chalk.red.bold("Failed:")} ${error.message}`);
|
||||
console.debug(`📚 ${chalk.blueBright.bold("Stack:")} ${error.stack}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue