|
@@ -1,3 +1,7 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * Build, update component.json, uglify, and report size.
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
module.exports = function (grunt) {
|
|
module.exports = function (grunt) {
|
|
|
grunt.registerTask('build', function () {
|
|
grunt.registerTask('build', function () {
|
|
|
|
|
|
|
@@ -19,8 +23,10 @@ module.exports = function (grunt) {
|
|
|
grunt.file.write('component.json', JSON.stringify(component, null, 2))
|
|
grunt.file.write('component.json', JSON.stringify(component, null, 2))
|
|
|
|
|
|
|
|
// then build
|
|
// then build
|
|
|
- build(grunt, function (js) {
|
|
|
|
|
- write('dist/vue.js', js)
|
|
|
|
|
|
|
+ build(grunt, function (err) {
|
|
|
|
|
+ if (err) return done(err)
|
|
|
|
|
+ var js = fs.readFileSync('dist/vue.js', 'utf-8')
|
|
|
|
|
+ report('dist/vue.js', js)
|
|
|
// uglify
|
|
// uglify
|
|
|
var result = uglifyjs.minify(js, {
|
|
var result = uglifyjs.minify(js, {
|
|
|
fromString: true,
|
|
fromString: true,
|
|
@@ -42,12 +48,16 @@ module.exports = function (grunt) {
|
|
|
// report gzip size
|
|
// report gzip size
|
|
|
zlib.gzip(result.code, function (err, buf) {
|
|
zlib.gzip(result.code, function (err, buf) {
|
|
|
write('dist/vue.min.js.gz', buf)
|
|
write('dist/vue.min.js.gz', buf)
|
|
|
- done()
|
|
|
|
|
|
|
+ done(err)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- function write (path, file, report) {
|
|
|
|
|
|
|
+ function write (path, file) {
|
|
|
fs.writeFileSync(path, file)
|
|
fs.writeFileSync(path, file)
|
|
|
|
|
+ report(path, file)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function report (path, file) {
|
|
|
console.log(
|
|
console.log(
|
|
|
blue(path + ': ') +
|
|
blue(path + ': ') +
|
|
|
(file.length / 1024).toFixed(2) + 'kb'
|
|
(file.length / 1024).toFixed(2) + 'kb'
|