Skip to content

Commit

Permalink
feat(build): add filesizes to output
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 2, 2017
1 parent 00c1ddc commit 7a6f30c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 16 additions & 4 deletions src/build/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
}
Expand All @@ -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(), {
Expand All @@ -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([{
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7a6f30c

Please sign in to comment.