-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbin.js
executable file
·55 lines (43 loc) · 1.43 KB
/
bin.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
#!/usr/bin/env node
import cac from 'cac'
import * as path from 'node:path'
import * as tmp from 'tmp'
import start from './index.js'
const cli = cac('vite-bundle-visualizer')
const tmpobj = tmp.dirSync();
const DEFAULT_OUTPUT = path.join(tmpobj.name, 'stats.html');
cli.help()
cli.option('--template -t <template>', 'Template to use, options are "raw-data" (JSON), "treemap", "list", "sunburst" and "network"', {
default: 'treemap'
})
cli.option('--output -o <filepath>', 'Output file path, should be "**/*.html" or "**/*.json"', {
default: DEFAULT_OUTPUT,
})
cli.option('--open <open>', 'Should open browser after generated, except when template is "json"', {
default: true
})
cli.option('--config -c <file>', 'Use specified vite config file')
cli.option('--entry --input -i', 'Use specified entry file, default is "index.html"')
cli.option('--sourcemap ', 'use sourcemap to calculate sizes of modules. By idea it will present more accurate results, defaults is false')
cli.option('--mode -m <mode>', 'set env mode, defaults to production')
const parsed = cli.parse()
const {
template, t,
h, help,
output, o,
open,
config, c,
entry, input, i,
sourcemap,
mode, m,
} = parsed.options
await start({
help: help || h,
template: template || t,
output: output || o || DEFAULT_OUTPUT,
open: open === true || open === 'true' || Number(open) > 0,
config: config || c,
entry: entry || input || i,
mode: mode || m,
sourcemap
})