-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
50 lines (44 loc) · 1.21 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
/**
* 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')
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'
}
})
}