forked from transitive-bullshit/microbundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog.js
70 lines (61 loc) · 2.51 KB
/
prog.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
import sade from 'sade';
let { version } = require('../package');
const toArray = val => (Array.isArray(val) ? val : val == null ? [] : [val]);
export default handler => {
const ENABLE_MODERN = process.env.MICROBUNDLE_MODERN !== 'false';
const DEFAULT_FORMATS = ENABLE_MODERN ? 'modern,es,cjs,umd' : 'es,cjs,umd';
const cmd = type => (str, opts) => {
opts.watch = opts.watch || type === 'watch';
opts.compress =
opts.compress != null ? opts.compress : opts.target !== 'node';
opts.entries = toArray(str || opts.entry).concat(opts._);
handler(opts);
};
let prog = sade('microbundle');
prog
.version(version)
.option('--entry, -i', 'Entry module(s)')
.option('--output, -o', 'Directory to place build files into')
.option('--format, -f', 'Only build specified formats', DEFAULT_FORMATS)
.option('--watch, -w', 'Rebuilds on any change', false)
.option('--target', 'Specify your target environment (node or web)', 'web')
.option('--external', `Specify external dependencies, or 'none'`)
.option('--globals', `Specify globals dependencies, or 'none'`)
.example('microbundle --globals react=React,jquery=$')
.option('--define', 'Replace constants with hard-coded values')
.example('microbundle --define API_KEY=1234')
.option('--alias', `Map imports to different modules`)
.example('microbundle --alias react=preact')
.option('--compress', 'Compress output using Terser', null)
.option('--strict', 'Enforce undefined global context and add "use strict"')
.option('--name', 'Specify name exposed in UMD builds')
.option('--cwd', 'Use an alternative working directory', '.')
.option('--sourcemap', 'Generate source map', true)
.option(
'--css-modules',
'Turns on css-modules for all .css imports. Passing a string will override the scopeName. eg --css-modules="_[hash]"',
null,
)
.example("microbundle --no-sourcemap # don't generate sourcemaps")
.option('--raw', 'Show raw byte size', false)
.option('--jsx', 'A custom JSX pragma (default React.createElement)')
.option('--tsconfig', 'Specify the path to a custom tsconfig.json')
.example('microbundle build --tsconfig tsconfig.build.json');
prog
.command('build [...entries]', '', { default: true })
.describe('Build once and exit')
.action(cmd('build'));
prog
.command('watch [...entries]')
.describe('Rebuilds on any change')
.action(cmd('watch'));
// Parse argv; add extra aliases
return argv =>
prog.parse(argv, {
alias: {
o: ['output', 'd'],
i: ['entry', 'entries', 'e'],
w: ['watch'],
},
});
};