Skip to content

Commit 2f93332

Browse files
authored
Merge pull request #16 from taylorli2000/main
enhancement: add cjs build
2 parents 5617f20 + b968eb5 commit 2f93332

File tree

5 files changed

+370
-25
lines changed

5 files changed

+370
-25
lines changed

build.mjs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
13
import { build } from 'esbuild';
2-
import { raw } from "esbuild-raw-plugin";
4+
import { raw } from 'esbuild-raw-plugin';
5+
import { es5Plugin } from 'esbuild-plugin-es5';
36

4-
const prod = build({
5-
entryPoints: ['src/index.ts'],
6-
bundle: true,
7-
format: 'esm',
8-
outfile: 'dist/esm/index.esm.js',
9-
sourcemap: true,
10-
minify: true,
11-
plugins: [raw()],
12-
target: ['ESNext'],
7+
const shared = {
8+
entryPoints: ['src/index.ts'],
9+
bundle: true,
10+
format: 'esm',
11+
sourcemap: true,
12+
minify: true,
13+
plugins: [raw()],
14+
target: ['ESNext'],
15+
tsconfig: 'tsconfig.esm.json',
16+
};
17+
18+
const prodESM = build({
19+
...shared,
20+
outfile: 'dist/esm/index.js',
1321
});
1422

15-
const demo = build({
16-
entryPoints: ['src/index.ts'],
17-
bundle: true,
18-
format: 'esm',
19-
outfile: 'demo/index.esm.js',
20-
sourcemap: true,
21-
minify: false,
22-
plugins: [raw()],
23+
const prodCJS = build({
24+
...shared,
25+
plugins: [...shared.plugins, es5Plugin()],
26+
target: ['es5'],
27+
alias: {
28+
'@swc/helpers': path.dirname(
29+
fileURLToPath(import.meta.resolve('@swc/helpers/package.json'))
30+
),
31+
},
32+
outfile: 'dist/cjs/index.cjs',
33+
tsconfig: 'tsconfig.cjs.json',
2334
});
2435

36+
const demo = build({
37+
...shared,
38+
outfile: 'demo/index.esm.js',
39+
minify: false,
40+
});
2541

26-
Promise.all([prod, demo]).catch(() => process.exit(1));
42+
Promise.all([prodESM, prodCJS, demo]).catch(() => process.exit(1));

package-lock.json

Lines changed: 275 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)