forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
69 lines (60 loc) · 1.78 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
/**
* Build and report size.
*/
module.exports = function (grunt) {
grunt.registerTask('build', function () {
var done = this.async()
var fs = require('fs')
var zlib = require('zlib')
var webpack = require('webpack')
var devConfig = require('../webpack.build.dev.config')
var prodConfig = require('../webpack.build.prod.config')
// handle version
var version = require('../../package.json').version
// add banner
var banner = new webpack.BannerPlugin(
'Vue.js v' + version + '\n' +
'(c) ' + new Date().getFullYear() + ' Evan You\n' +
'Released under the MIT License.'
)
devConfig.plugins.unshift(banner)
prodConfig.plugins.unshift(banner)
// update main file
var main = fs
.readFileSync('src/vue.js', 'utf-8')
.replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
fs.writeFileSync('src/vue.js', main)
// build
webpack(devConfig, function (err, stats) {
if (err) return done(err)
report('dist/vue.js')
webpack(prodConfig, function (err, stats) {
if (err) return done(err)
report('dist/vue.min.js')
zip()
})
})
function zip () {
fs.readFile('dist/vue.min.js', function (err, buf) {
if (err) return done(err)
zlib.gzip(buf, function (err, buf) {
if (err) return done(err)
report('dist/vue.min.js.gz', buf)
fs.writeFile('dist/vue.min.js.gz', buf, done)
})
})
}
function report (path, file) {
if (!file) {
file = fs.readFileSync(path)
}
console.log(
blue(path + ': ') +
(file.length / 1024).toFixed(2) + 'kb'
)
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}
})
}