forked from qiu8310/mora-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·53 lines (47 loc) · 1.14 KB
/
build
File metadata and controls
executable file
·53 lines (47 loc) · 1.14 KB
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
#!/usr/bin/env node
/**
* 打包指定的模块
*
* @required webpack
*
* @module build
* @createdAt 2016-08-05
*
* @copyright Copyright (c) 2016 Zhonglei Qiu
* @license Licensed under the MIT license.
*/
var cp = require('child_process')
var path = require('path')
var cli = require('./libs/tty/cli')
cli({
strict: true,
usage: 'build <path/to/filename> [options]',
version: '1.1.0',
epilog: 'Copyright Mora'
})
.options({
'm | min': '<boolean> minify source file',
'o | outDir': '<string> specified output directory, default is `dist` directory'
})
.parse(function (res) {
if (!res._.length) return this.help()
var outDir = path.resolve(res.outDir || 'dist')
res._.forEach(function (file) {
build(file, path.join(outDir, path.basename(file)))
})
if (res.min) {
res._.forEach(function (file) {
build(file, path.join(outDir, path.basename(file).replace(/\.js$/, '.min.js')), true)
})
}
})
function build (entry, outfile, min) {
var args = [
entry,
outfile,
'--output-library-target',
'commonjs2'
]
if (min) args.push('-p')
cp.spawn('webpack', args, {stdio: 'inherit'})
}