forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
71 lines (64 loc) · 1.74 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Build, update component.json, uglify, and report size.
*/
module.exports = function (grunt) {
grunt.registerTask('build', function () {
var done = this.async()
var fs = require('fs')
var zlib = require('zlib')
var build = require('../shared-build')
var uglifyjs = require('uglify-js')
// update component.json first
var jsRE = /\.js$/
var component = grunt.file.readJSON('component.json')
component.scripts = []
grunt.file.recurse('src', function (file) {
if (jsRE.test(file)) {
component.scripts.push(file)
}
})
grunt.file.write('component.json', JSON.stringify(component, null, 2))
// then build
build(grunt, function (err) {
if (err) return done(err)
var js = fs.readFileSync('dist/vue.js', 'utf-8')
report('dist/vue.js', js)
// uglify
var result = uglifyjs.minify(js, {
fromString: true,
output: {
comments: /License/
},
compress: {
pure_funcs: [
'require',
'_.log',
'_.warn',
'_.assertAsset',
'enableDebug'
]
}
})
// var min = grunt.config.get('banner') + result.code
write('dist/vue.min.js', result.code)
// report gzip size
zlib.gzip(result.code, function (err, buf) {
write('dist/vue.min.js.gz', buf)
done(err)
})
})
function write (path, file) {
fs.writeFileSync(path, file)
report(path, file)
}
function report (path, file) {
console.log(
blue(path + ': ') +
(file.length / 1024).toFixed(2) + 'kb'
)
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}
})
}