mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[kbn/ui-shared-deps] track asset sizes (#78718)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
4c4d28ad35
commit
353595617b
1 changed files with 37 additions and 8 deletions
|
@ -18,18 +18,21 @@
|
|||
*/
|
||||
|
||||
const Path = require('path');
|
||||
const Fs = require('fs');
|
||||
|
||||
const { run, createFailError } = require('@kbn/dev-utils');
|
||||
const { run, createFailError, CiStatsReporter } = require('@kbn/dev-utils');
|
||||
const webpack = require('webpack');
|
||||
const Stats = require('webpack/lib/Stats');
|
||||
const del = require('del');
|
||||
|
||||
const { getWebpackConfig } = require('../webpack.config');
|
||||
|
||||
const DIST_DIR = Path.resolve(__dirname, '../target');
|
||||
|
||||
run(
|
||||
async ({ log, flags }) => {
|
||||
log.info('cleaning previous build output');
|
||||
await del(Path.resolve(__dirname, '../target'));
|
||||
await del(DIST_DIR);
|
||||
|
||||
const compiler = webpack(
|
||||
getWebpackConfig({
|
||||
|
@ -38,10 +41,38 @@ run(
|
|||
);
|
||||
|
||||
/** @param {webpack.Stats} stats */
|
||||
const onCompilationComplete = (stats) => {
|
||||
const onCompilationComplete = async (stats) => {
|
||||
const took = Math.round((stats.endTime - stats.startTime) / 1000);
|
||||
|
||||
if (!stats.hasErrors() && !stats.hasWarnings()) {
|
||||
if (!flags.dev) {
|
||||
const reporter = CiStatsReporter.fromEnv(log);
|
||||
|
||||
const metrics = [
|
||||
{
|
||||
group: '@kbn/ui-shared-deps asset size',
|
||||
id: 'kbn-ui-shared-deps.js',
|
||||
value: Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.js')).size,
|
||||
},
|
||||
{
|
||||
group: '@kbn/ui-shared-deps asset size',
|
||||
id: 'kbn-ui-shared-deps.@elastic.js',
|
||||
value: Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.@elastic.js')).size,
|
||||
},
|
||||
{
|
||||
group: '@kbn/ui-shared-deps asset size',
|
||||
id: 'css',
|
||||
value:
|
||||
Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.css')).size +
|
||||
Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.v7.light.css')).size,
|
||||
},
|
||||
];
|
||||
|
||||
log.debug('metrics:', metrics);
|
||||
|
||||
await reporter.metrics(metrics);
|
||||
}
|
||||
|
||||
log.success(`webpack completed in about ${took} seconds`);
|
||||
return;
|
||||
}
|
||||
|
@ -56,11 +87,9 @@ run(
|
|||
|
||||
if (flags.watch) {
|
||||
compiler.hooks.done.tap('report on stats', (stats) => {
|
||||
try {
|
||||
onCompilationComplete(stats);
|
||||
} catch (error) {
|
||||
onCompilationComplete(stats).catch((error) => {
|
||||
log.error(error.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
compiler.hooks.watchRun.tap('report on start', () => {
|
||||
|
@ -83,7 +112,7 @@ run(
|
|||
return;
|
||||
}
|
||||
|
||||
onCompilationComplete(
|
||||
await onCompilationComplete(
|
||||
await new Promise((resolve, reject) => {
|
||||
compiler.run((error, stats) => {
|
||||
if (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue