@@ -20,32 +20,63 @@ process.on( 'unhandledRejection', err => {
2020 throw err ;
2121} ) ;
2222
23+ // Modules.
24+ const fs = require ( 'fs' ) ;
2325const ora = require ( 'ora' ) ;
26+ const path = require ( 'path' ) ;
2427const chalk = require ( 'chalk' ) ;
2528const webpack = require ( 'webpack' ) ;
26- const config = require ( '../config/webpack.config.dev' ) ;
29+ const fileSize = require ( 'filesize' ) ;
30+ const gzipSize = require ( 'gzip-size' ) ;
2731const resolvePkg = require ( 'resolve-pkg' ) ;
32+ const config = require ( '../config/webpack.config.prod' ) ;
2833const cgbDevUtilsPath = resolvePkg ( 'cgb-dev-utils' , { cwd : __dirname } ) ;
2934const clearConsole = require ( cgbDevUtilsPath + '/clearConsole' ) ;
3035const formatWebpackMessages = require ( cgbDevUtilsPath +
3136 '/formatWebpackMessages' ) ;
3237
38+ // Build file paths.
39+ const theCWD = process . cwd ( ) ;
40+ const fileBuildJS = path . resolve ( theCWD , './dist/blocks.build.js' ) ;
41+ const fileEditorCSS = path . resolve ( theCWD , './dist/blocks.editor.build.css' ) ;
42+ const fileStyleCSS = path . resolve ( theCWD , './dist/blocks.style.build.css' ) ;
43+
44+ /**
45+ * Get File Size
46+ *
47+ * Get filesizes of all the files.
48+ *
49+ * @param {string } filePath path.
50+ * @returns {string } then size result.
51+ */
52+ const getFileSize = filePath => {
53+ return fileSize ( gzipSize . sync ( fs . readFileSync ( filePath ) ) ) ;
54+ } ;
55+
3356clearConsole ( ) ;
3457
3558// Init the spinner.
3659const spinner = new ora ( {
3760 text : '' ,
3861 enabled : true ,
3962} ) ;
40- // Create the production build and print the deployment instructions.
63+
64+ /**
65+ * Build function
66+ *
67+ * Create the production build and print the deployment instructions.
68+ *
69+ * @param {json } webpackConfig config
70+ */
4171async function build ( webpackConfig ) {
72+ // Start the build.
4273 spinner . start ( `${ chalk . dim ( 'Building and compiling blocks...' ) } ` ) ;
4374
4475 // Compiler Instance.
4576 const compiler = await webpack ( webpackConfig ) ;
4677 spinner . succeed ( ) ;
4778
48- compiler . run ( { } , ( err , stats ) => {
79+ compiler . run ( ( err , stats ) => {
4980 if ( err ) {
5081 return console . log ( err ) ;
5182 }
@@ -84,7 +115,29 @@ async function build( webpackConfig ) {
84115 }
85116
86117 clearConsole ( ) ;
87- return console . log ( '\n✅ ' , chalk . black . bgGreen ( ' Built successfully! \n' ) ) ;
118+ console . log ( '\n✅ ' , chalk . black . bgGreen ( ' Built successfully! \n' ) ) ;
119+
120+ console . log (
121+ '\n\n' ,
122+ 'File sizes after gzip:' ,
123+ '\n\n' ,
124+ getFileSize ( fileBuildJS ) ,
125+ `${ chalk . dim ( '— ./dist/' ) } ` ,
126+ `${ chalk . green ( 'blocks.build.js' ) } ` ,
127+ '\n' ,
128+ getFileSize ( fileEditorCSS ) ,
129+ `${ chalk . dim ( '— ./dist/' ) } ` ,
130+ `${ chalk . green ( 'blocks.editor.build.css' ) } ` ,
131+
132+ '\n' ,
133+ getFileSize ( fileStyleCSS ) ,
134+ `${ chalk . dim ( '— ./dist/' ) } ` ,
135+ `${ chalk . green ( 'blocks.style.build.css' ) } ` ,
136+
137+ '\n\n'
138+ ) ;
139+
140+ return true ;
88141 } ) ;
89142}
90143
0 commit comments