-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.mjs
executable file
·36 lines (32 loc) · 1.11 KB
/
esbuild.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
import * as esbuild from 'esbuild';
import CssModulesPlugin from 'esbuild-css-modules-plugin';
import packageJson from './package.json' with {type: 'json'};
// Options for both, cjs and esm builds
const sharedBuildOptions = {
bundle: true,
entryPoints: ['src/index.ts'],
// Treat all dependencies in package.json as externals to keep bundle size to a minimum
external: [...Object.keys(packageJson.dependencies || {}), ...Object.keys(packageJson.peerDependencies || {})],
logLevel: "info",
minify: true,
sourcemap: true,
plugins: [
// @see https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/index.d.ts for possible options
CssModulesPlugin({})
]
};
// build cjs.
esbuild.build({
...sharedBuildOptions,
format: "cjs",
outfile: "./dist/cjs/index.js",
target: ["esnext", "node22"],
}).then(() => console.log('finished cjs build.'))
// build esm.
esbuild.build({
...sharedBuildOptions,
format: "esm",
outfile: "./dist/esm/index.js",
target: ["esnext", "node22"],
}).then(() => console.log('finished esm build.'))