-
-
Notifications
You must be signed in to change notification settings - Fork 375
/
build.js
56 lines (49 loc) · 1.23 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
import { resolve } from 'path';
import promisify from 'es6-promisify';
import rimraf from 'rimraf';
import asyncCommand from '../lib/async-command';
import webpackConfig from '../lib/webpack-config';
import runWebpack, { showStats, writeJsonStats } from '../lib/run-webpack';
export default asyncCommand({
command: 'build [src] [dest]',
desc: 'Create a production build in build/',
builder: {
src: {
description: 'Entry file (index.js)',
default: 'src'
},
dest: {
description: 'Directory root for output',
default: 'build'
},
production: {
description: 'Create a minified production build.',
alias: 'p',
default: true
},
prerender: {
description: 'Pre-render static app content.',
default: true
},
clean: {
description: 'Clear output directory before building.',
default: true
},
json: {
description: 'Generate build statistics for analysis.',
default: false
}
},
async handler(argv) {
let config = webpackConfig(argv);
if (argv.clean) {
let dest = resolve(argv.cwd || process.cwd(), argv.dest || 'build');
await promisify(rimraf)(dest);
}
let stats = await runWebpack(false, config);
showStats(stats);
if (argv.json) {
await writeJsonStats(stats)
}
}
});