forked from jhildenbiddle/mergician
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
79 lines (67 loc) · 1.84 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
const esbuild = require('esbuild');
const pkg = { ...require('./package.json') };
const isWatch = process.argv.includes('--watch');
// Copyright
const currentYear = (new Date()).getFullYear();
const releaseYear = 2022;
// Banner
const bannerData = [
`${pkg.name}`,
`v${pkg.version}`,
`${pkg.homepage}`,
`(c) ${releaseYear}${currentYear === releaseYear ? '' : '-' + currentYear} ${pkg.author}`,
`${pkg.license} license`
];
// Config
// =============================================================================
// Base
const config = {
entryPoints: ['src/index.cjs'],
bundle: true,
banner: {
js: `/*!\n * ${ bannerData.join('\n * ') }\n */`
},
legalComments: 'inline',
target: ['esnext'],
outfile: 'dist/mergician.js',
watch: isWatch,
};
const cjs = {
...config,
format: 'cjs',
outfile: config.outfile.replace(/\.js$/, '.cjs'),
};
const esm = {
...config,
format: 'esm',
outfile: config.outfile.replace(/\.js$/, '.mjs'),
};
const esmMinified = {
...esm,
minify: true,
legalComments: 'none',
sourcemap: true,
outfile: config.outfile.replace(/\.js$/, '.min.mjs'),
};
const jsMinified = {
...config,
format: 'iife',
globalName: 'mergician',
minify: true,
legalComments: 'none',
sourcemap: true,
outfile: config.outfile.replace(/\.js$/, '.min.js'),
};
// Build
// =============================================================================
// eslint-disable-next-line no-console
console.log(`esbuild: ${isWatch ? 'watching' : 'building'}...`);
[cjs, esm, esmMinified, jsMinified].forEach(config => {
esbuild
.build(config)
.then(() => {
// eslint-disable-next-line no-console
console.log(`esbuild: ${config.entryPoints} => ${config.outfile}`);
})
.catch(() => process.exit(1));
});