Skip to content

Commit 7a6f30c

Browse files
feat(build): add filesizes to output
1 parent 00c1ddc commit 7a6f30c

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"detect-node": "^2.0.3",
4242
"eslint": "^4.1.1",
4343
"eslint-config-aegir": "^1.0.1",
44+
"filesize": "^3.5.10",
4445
"fs-extra": "^3.0.1",
4546
"glob": "^7.1.2",
4647
"gulp": "^3.9.1",

src/build/browser.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ const Uglify = require('uglify-es')
55
const path = require('path')
66
const Listr = require('listr')
77
const fs = require('fs-extra')
8+
const filesize = require('filesize')
89

910
const clean = require('../clean')
1011

1112
const WEBPACK_CONFIG = require('../../config/webpack')
1213

13-
function webpackBuild (ctx) {
14+
function webpackBuild (ctx, task) {
1415
return new Promise((resolve, reject) => {
1516
webpack(WEBPACK_CONFIG, (err, stats) => {
1617
if (err) {
1718
return reject(err)
1819
}
1920
ctx.webpackResult = stats
20-
resolve(stats)
21+
22+
const assets = stats.toJson().assets
23+
.filter((asset) => /\.(js)$/.test(asset.name))
24+
25+
task.title += ` (${filesize(assets[0].size)})`
26+
resolve('finished')
2127
})
2228
})
2329
}
@@ -30,7 +36,9 @@ function writeStats (ctx) {
3036
)
3137
}
3238

33-
function minify () {
39+
function minify (ctx, task) {
40+
const minifiedPath = path.join(process.cwd(), 'dist', 'index.min.js')
41+
3442
return fs.readFile(path.join(process.cwd(), 'dist', 'index.js'))
3543
.then((code) => {
3644
const result = Uglify.minify(code.toString(), {
@@ -43,10 +51,14 @@ function minify () {
4351
})
4452
.then((minified) => {
4553
return fs.writeFile(
46-
path.join(process.cwd(), 'dist', 'index.min.js'),
54+
minifiedPath,
4755
minified
4856
)
4957
})
58+
.then(() => fs.stat(minifiedPath))
59+
.then((stats) => {
60+
task.title += ` (${filesize(stats.size)})`
61+
})
5062
}
5163

5264
const TASKS = new Listr([{

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,10 @@ filename-regex@^2.0.0:
28772877
version "2.0.1"
28782878
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
28792879

2880+
filesize@^3.5.10:
2881+
version "3.5.10"
2882+
resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.5.10.tgz#fc8fa23ddb4ef9e5e0ab6e1e64f679a24a56761f"
2883+
28802884
fill-range@^2.1.0:
28812885
version "2.2.3"
28822886
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-2.2.3.tgz#50b77dfd7e469bc7492470963699fe7a8485a723"

0 commit comments

Comments
 (0)