9
9
10
10
process . env . NODE_ENV = 'production' ;
11
11
12
+ var fs = require ( 'fs' ) ;
13
+ var filesize = require ( 'filesize' ) ;
14
+ var gzipSize = require ( 'gzip-size' ) ;
12
15
var rimrafSync = require ( 'rimraf' ) . sync ;
13
16
var webpack = require ( 'webpack' ) ;
14
17
var config = require ( '../config/webpack.config.prod' ) ;
@@ -18,6 +21,16 @@ var paths = require('../config/paths');
18
21
// if you're in it, you don't end up in Trash
19
22
rimrafSync ( paths . appBuild + '/*' ) ;
20
23
24
+ function logBuildSize ( assets , extension ) {
25
+ for ( var i = 0 ; i < assets . length ; i ++ ) {
26
+ var asset = assets [ i ] ;
27
+ if ( asset . name . endsWith ( '.' + extension ) ) {
28
+ var fileContents = fs . readFileSync ( paths . appBuild + '/' + asset . name ) ;
29
+ console . log ( 'Size (gzipped) of ' + asset . name + ': ' + filesize ( gzipSize . sync ( fileContents ) ) ) ;
30
+ }
31
+ }
32
+ }
33
+
21
34
webpack ( config ) . run ( function ( err , stats ) {
22
35
if ( err ) {
23
36
console . error ( 'Failed to create a production build. Reason:' ) ;
@@ -48,6 +61,9 @@ webpack(config).run(function(err, stats) {
48
61
console . log ( ' pushstate-server build' ) ;
49
62
console . log ( ' ' + openCommand + ' http://localhost:9000' ) ;
50
63
console . log ( ) ;
64
+ var assets = stats . toJson ( ) [ 'assets' ] ;
65
+ logBuildSize ( assets , 'js' ) ;
66
+ logBuildSize ( assets , 'css' ) ;
51
67
}
52
68
console . log ( 'The bundle is optimized and ready to be deployed to production.' ) ;
53
69
} ) ;
0 commit comments