-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
82 lines (71 loc) · 2.01 KB
/
build.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const { execSync } = require('node:child_process');
const entryPoints = [
'src/index.ts',
'src/join-strings.ts',
'src/keys-to-strings.ts',
'src/merge-module-strings.ts',
'src/merge-styles.ts',
];
const shared = {
bundle: true,
sourcemap: true,
target: ['es2015'],
plugins: [nodeExternalsPlugin()],
};
function toCamelCase(str) {
return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
}
async function build() {
for (const entryPoint of entryPoints) {
const name = entryPoint.split('/').pop().replace('.ts', '');
const camelCaseName = toCamelCase(name);
// ESM and CJS builds (as before)
await esbuild.build({
...shared,
entryPoints: [entryPoint],
outfile: `dist/esm/${name}.js`,
format: 'esm',
});
await esbuild.build({
...shared,
entryPoints: [entryPoint],
outfile: `dist/${name}.js`,
format: 'cjs',
});
// UMD builds
const globalName =
name === 'index'
? 'classG'
: `classG${camelCaseName.charAt(0).toUpperCase() + camelCaseName.slice(1)}`;
await esbuild.build({
...shared,
entryPoints: [entryPoint],
outfile: `dist/umd/${name}.js`,
format: 'iife',
globalName: globalName,
footer: {
js: `if(typeof module==="object"&&module.exports)module.exports=${globalName};`,
},
});
// Minified UMD builds
await esbuild.build({
...shared,
entryPoints: [entryPoint],
outfile: `dist/umd/${name}.min.js`,
format: 'iife',
globalName: globalName,
footer: {
js: `if(typeof module==="object"&&module.exports)module.exports=${globalName};`,
},
minify: true,
});
}
// Generate declaration files
execSync('tsc -p tsconfig.json --emitDeclarationOnly', { stdio: 'inherit' });
execSync('tsc -p tsconfig.esm.json --emitDeclarationOnly', {
stdio: 'inherit',
});
}
build().catch(() => process.exit(1));