build(analytics): track bundle size
This will send bundle sizes (before and after gzip) to Google Analytics so that we can track bundle size over time for every bundle we produce. Closes #5294
This commit is contained in:
33
gulpfile.js
33
gulpfile.js
@ -1045,6 +1045,37 @@ gulp.task('!bundle.copy', function() {
|
||||
gulp.src('dist/js/bundle/**').pipe(gulp.dest('dist/js/dev/es5/bundle')));
|
||||
});
|
||||
|
||||
gulp.task('!bundles.js.checksize', function() {
|
||||
var gzip = require('gulp-gzip');
|
||||
var path = require('path');
|
||||
|
||||
return merge2(gulp.src('dist/js/bundle/**').on('data', checkFileSizeFactory('uncompressed')),
|
||||
gulp.src('dist/js/bundle/**')
|
||||
.pipe(gzip({gzipOptions: {level: 1}})) // code.angular.js
|
||||
.on('data', checkFileSizeFactory('gzip level=1')),
|
||||
gulp.src('dist/js/bundle/**')
|
||||
.pipe(gzip({gzipOptions: {level: 2}})) // github pages, most common
|
||||
.on('data', checkFileSizeFactory('gzip level=2', true)),
|
||||
gulp.src('dist/js/bundle/**')
|
||||
.pipe(gzip({gzipOptions: {level: 6}})) // default gzip level
|
||||
.on('data', checkFileSizeFactory('gzip level=6')),
|
||||
gulp.src('dist/js/bundle/**')
|
||||
.pipe(gzip({gzipOptions: {level: 9}})) // max gzip level
|
||||
.on('data', checkFileSizeFactory('gzip level=9')));
|
||||
|
||||
function checkFileSizeFactory(compressionLevel, printToConsole) {
|
||||
return function checkFileSize(file) {
|
||||
if (file.isNull()) return;
|
||||
var filePath =
|
||||
path.relative(path.join('dist', 'js', 'bundle'), file.path).replace('\.gz', '');
|
||||
analytics.bundleSize(filePath, file.contents.length, compressionLevel);
|
||||
if (printToConsole) {
|
||||
console.log(` ${filePath} => ${file.contents.length} bytes (${compressionLevel})`)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
gulp.task('bundles.js',
|
||||
[
|
||||
'!bundle.js.prod.deps',
|
||||
@ -1054,7 +1085,7 @@ gulp.task('bundles.js',
|
||||
'!bundle.js.sfx.dev.deps',
|
||||
'!bundle.testing'
|
||||
],
|
||||
function(done) { runSequence('!bundle.copy', done); });
|
||||
function(done) { runSequence('!bundle.copy', '!bundles.js.checksize', done); });
|
||||
|
||||
gulp.task('build.js',
|
||||
['build.js.dev', 'build.js.prod', 'build.js.cjs', 'bundles.js', 'benchpress.bundle']);
|
||||
|
Reference in New Issue
Block a user