|
1 | 1 | import { build } from 'esbuild';
|
2 | 2 | import { writeFile } from 'node:fs/promises';
|
3 | 3 |
|
| 4 | +const builds = []; |
| 5 | + |
4 | 6 | // Bundled CJS
|
5 |
| -build({ |
6 |
| - entryPoints: ['./src/index.js'], |
7 |
| - logLevel: 'info', |
8 |
| - bundle: true, |
9 |
| - format: 'cjs', |
10 |
| - outfile: 'bundled/culori.cjs' |
11 |
| -}); |
| 7 | +builds.push( |
| 8 | + build({ |
| 9 | + entryPoints: ['./src/index.js'], |
| 10 | + logLevel: 'info', |
| 11 | + bundle: true, |
| 12 | + format: 'cjs', |
| 13 | + outfile: 'bundled/culori.cjs' |
| 14 | + }) |
| 15 | +); |
12 | 16 |
|
13 | 17 | // Bundled CJS, minified
|
14 |
| -build({ |
15 |
| - entryPoints: ['./src/index.js'], |
16 |
| - logLevel: 'info', |
17 |
| - bundle: true, |
18 |
| - minify: true, |
19 |
| - format: 'cjs', |
20 |
| - outfile: 'bundled/culori.min.cjs' |
21 |
| -}); |
| 18 | +builds.push( |
| 19 | + build({ |
| 20 | + entryPoints: ['./src/index.js'], |
| 21 | + logLevel: 'info', |
| 22 | + bundle: true, |
| 23 | + minify: true, |
| 24 | + format: 'cjs', |
| 25 | + outfile: 'bundled/culori.min.cjs' |
| 26 | + }) |
| 27 | +); |
22 | 28 |
|
23 | 29 | // Bundled ESM
|
24 |
| -build({ |
25 |
| - entryPoints: ['./src/index.js'], |
26 |
| - logLevel: 'info', |
27 |
| - bundle: true, |
28 |
| - format: 'esm', |
29 |
| - metafile: true, |
30 |
| - outfile: 'bundled/culori.mjs' |
31 |
| -}).then(result => { |
32 |
| - writeFile('bundled/meta.json', JSON.stringify(result.metafile, null, 2)); |
33 |
| -}); |
| 30 | +builds.push( |
| 31 | + build({ |
| 32 | + entryPoints: ['./src/index.js'], |
| 33 | + logLevel: 'info', |
| 34 | + bundle: true, |
| 35 | + format: 'esm', |
| 36 | + metafile: true, |
| 37 | + outfile: 'bundled/culori.mjs' |
| 38 | + }).then(result => { |
| 39 | + writeFile( |
| 40 | + 'bundled/meta.json', |
| 41 | + JSON.stringify(result.metafile, null, 2) |
| 42 | + ); |
| 43 | + }) |
| 44 | +); |
34 | 45 |
|
35 | 46 | // Bundled ESM, minified
|
36 |
| -build({ |
37 |
| - entryPoints: ['./src/index.js'], |
38 |
| - logLevel: 'info', |
39 |
| - bundle: true, |
40 |
| - minify: true, |
41 |
| - format: 'esm', |
42 |
| - outfile: 'bundled/culori.min.mjs' |
43 |
| -}); |
| 47 | +builds.push( |
| 48 | + build({ |
| 49 | + entryPoints: ['./src/index.js'], |
| 50 | + logLevel: 'info', |
| 51 | + bundle: true, |
| 52 | + minify: true, |
| 53 | + format: 'esm', |
| 54 | + outfile: 'bundled/culori.min.mjs' |
| 55 | + }) |
| 56 | +); |
44 | 57 |
|
45 | 58 | // Bundled IIFE
|
46 |
| -build({ |
47 |
| - entryPoints: ['./src/index.js'], |
48 |
| - logLevel: 'info', |
49 |
| - bundle: true, |
50 |
| - format: 'iife', |
51 |
| - globalName: 'culori', |
52 |
| - outfile: 'bundled/culori.js' |
53 |
| -}); |
| 59 | +builds.push( |
| 60 | + build({ |
| 61 | + entryPoints: ['./src/index.js'], |
| 62 | + logLevel: 'info', |
| 63 | + bundle: true, |
| 64 | + format: 'iife', |
| 65 | + globalName: 'culori', |
| 66 | + outfile: 'bundled/culori.js' |
| 67 | + }) |
| 68 | +); |
54 | 69 |
|
55 | 70 | // Bundled IIFE, minified
|
56 |
| -build({ |
57 |
| - entryPoints: ['./src/index.js'], |
58 |
| - logLevel: 'info', |
59 |
| - bundle: true, |
60 |
| - minify: true, |
61 |
| - format: 'iife', |
62 |
| - globalName: 'culori', |
63 |
| - outfile: 'bundled/culori.min.js' |
64 |
| -}); |
| 71 | +builds.push( |
| 72 | + build({ |
| 73 | + entryPoints: ['./src/index.js'], |
| 74 | + logLevel: 'info', |
| 75 | + bundle: true, |
| 76 | + minify: true, |
| 77 | + format: 'iife', |
| 78 | + globalName: 'culori', |
| 79 | + outfile: 'bundled/culori.min.js' |
| 80 | + }) |
| 81 | +); |
65 | 82 |
|
66 | 83 | // Bundled UMD
|
67 | 84 | // Adapted from: https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
68 |
| -build({ |
69 |
| - entryPoints: ['./src/index.js'], |
70 |
| - logLevel: 'info', |
71 |
| - bundle: true, |
72 |
| - format: 'iife', |
73 |
| - globalName: 'culori', |
74 |
| - banner: { |
75 |
| - js: `(function(root, factory) { |
76 |
| - if (typeof define === 'function' && define.amd) { |
77 |
| - define([], factory); |
78 |
| - } else if (typeof module === 'object' && module.exports) { |
79 |
| - module.exports = factory(); |
80 |
| - } else { |
81 |
| - root.culori = factory(); |
| 85 | +builds.push( |
| 86 | + build({ |
| 87 | + entryPoints: ['./src/index.js'], |
| 88 | + logLevel: 'info', |
| 89 | + bundle: true, |
| 90 | + format: 'iife', |
| 91 | + globalName: 'culori', |
| 92 | + banner: { |
| 93 | + js: `(function(root, factory) { |
| 94 | + if (typeof define === 'function' && define.amd) { |
| 95 | + define([], factory); |
| 96 | + } else if (typeof module === 'object' && module.exports) { |
| 97 | + module.exports = factory(); |
| 98 | + } else { |
| 99 | + root.culori = factory(); |
| 100 | + } |
82 | 101 | }
|
83 |
| - } |
84 |
| - (typeof self !== 'undefined' ? self : this, function() {` |
85 |
| - }, |
86 |
| - footer: { js: `return culori; }));` }, |
87 |
| - outfile: 'bundled/culori.umd.js' |
88 |
| -}); |
| 102 | + (typeof self !== 'undefined' ? self : this, function() {` |
| 103 | + }, |
| 104 | + footer: { js: `return culori; }));` }, |
| 105 | + outfile: 'bundled/culori.umd.js' |
| 106 | + }) |
| 107 | +); |
| 108 | + |
| 109 | +await Promise.all(builds); |
0 commit comments