forked from GoogleChromeLabs/browser-fs-access
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
60 lines (53 loc) · 1.3 KB
/
esbuild.config.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
/* eslint-disable */
const fs = require('fs');
const esbuild = require('esbuild');
const { gzip } = require('zlib');
const name = process.env.npm_package_name || '';
async function main() {
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e;
}
});
}
try {
esbuild.buildSync({
entryPoints: ['./src/index.js'],
outdir: 'dist/cjs',
minify: true,
bundle: true,
format: 'cjs',
target: 'es6',
external: [],
metafile: true,
});
const esmResult = esbuild.buildSync({
entryPoints: ['./src/index.js'],
outdir: 'dist/esm',
minify: true,
bundle: true,
format: 'esm',
target: 'es6',
external: [],
metafile: true,
});
let esmSize = 0;
Object.values(esmResult.metafile.outputs).forEach((output) => {
esmSize += output.bytes;
});
fs.readFile('./dist/esm/index.js', (_err, data) => {
gzip(data, (_err, result) => {
console.log(
`✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
result.length / 1000
).toFixed(2)}kb minified)`
);
});
});
} catch (e) {
console.log(`× ${name}: Build failed due to an error.`);
console.log(e);
}
}
main();