-
Notifications
You must be signed in to change notification settings - Fork 11
/
pkg.js
45 lines (37 loc) · 932 Bytes
/
pkg.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
import { readFileSync, writeFileSync, cpSync } from 'node:fs';
import { join } from 'node:path';
import { rollup } from 'rollup';
import { exec } from 'pkg';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
const bundle = await rollup({
input: 'dist/cli.js',
plugins: [
nodeResolve({
exportConditions: ['node'],
}),
commonjs(),
json(),
],
});
await bundle.write({
dir: 'bundle',
format: 'cjs',
});
await bundle.close();
const pkgJson = JSON.parse(readFileSync('package.json', 'utf8'));
delete pkgJson.type;
pkgJson.pkg.assets.forEach((asset) => {
cpSync(join('dist', asset), join('bundle', asset));
});
writeFileSync('bundle/package.json', JSON.stringify(pkgJson, null, 2));
await exec([
'bundle',
'--out-path',
'bundle',
'--compress',
'brotli',
'--options',
'no-warnings',
]);