diff --git a/package.json b/package.json index 7c5be08bf..87f93d6f6 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "detect-node": "^2.0.3", "eslint": "^4.1.1", "eslint-config-aegir": "^1.0.1", + "filesize": "^3.5.10", "fs-extra": "^3.0.1", "glob": "^7.1.2", "gulp": "^3.9.1", diff --git a/src/build/browser.js b/src/build/browser.js index 3c56dfeef..ba414370e 100644 --- a/src/build/browser.js +++ b/src/build/browser.js @@ -5,19 +5,25 @@ const Uglify = require('uglify-es') const path = require('path') const Listr = require('listr') const fs = require('fs-extra') +const filesize = require('filesize') const clean = require('../clean') const WEBPACK_CONFIG = require('../../config/webpack') -function webpackBuild (ctx) { +function webpackBuild (ctx, task) { return new Promise((resolve, reject) => { webpack(WEBPACK_CONFIG, (err, stats) => { if (err) { return reject(err) } ctx.webpackResult = stats - resolve(stats) + + const assets = stats.toJson().assets + .filter((asset) => /\.(js)$/.test(asset.name)) + + task.title += ` (${filesize(assets[0].size)})` + resolve('finished') }) }) } @@ -30,7 +36,9 @@ function writeStats (ctx) { ) } -function minify () { +function minify (ctx, task) { + const minifiedPath = path.join(process.cwd(), 'dist', 'index.min.js') + return fs.readFile(path.join(process.cwd(), 'dist', 'index.js')) .then((code) => { const result = Uglify.minify(code.toString(), { @@ -43,10 +51,14 @@ function minify () { }) .then((minified) => { return fs.writeFile( - path.join(process.cwd(), 'dist', 'index.min.js'), + minifiedPath, minified ) }) + .then(() => fs.stat(minifiedPath)) + .then((stats) => { + task.title += ` (${filesize(stats.size)})` + }) } const TASKS = new Listr([{ diff --git a/yarn.lock b/yarn.lock index 9e6b349cb..99ca746e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2877,6 +2877,10 @@ filename-regex@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" +filesize@^3.5.10: + version "3.5.10" + resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.5.10.tgz#fc8fa23ddb4ef9e5e0ab6e1e64f679a24a56761f" + fill-range@^2.1.0: version "2.2.3" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-2.2.3.tgz#50b77dfd7e469bc7492470963699fe7a8485a723"