|
| 1 | +import path from 'path'; |
| 2 | +import { fileURLToPath } from 'url'; |
1 | 3 | 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'; |
3 | 6 |
|
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', |
13 | 21 | }); |
14 | 22 |
|
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', |
23 | 34 | }); |
24 | 35 |
|
| 36 | +const demo = build({ |
| 37 | + ...shared, |
| 38 | + outfile: 'demo/index.esm.js', |
| 39 | + minify: false, |
| 40 | +}); |
25 | 41 |
|
26 | | -Promise.all([prod, demo]).catch(() => process.exit(1)); |
| 42 | +Promise.all([prodESM, prodCJS, demo]).catch(() => process.exit(1)); |
0 commit comments