1.2.0 ā€¢ Published 2 years ago

@fluentui/bundle-size v1.2.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

@fluentui/bundle-size

A CLI tool to measure bundle size locally and on CI.

NOTE: bundle-size requires to build packages first before doing any kind of measurements. Make sure to accommodate this in your pipeline

Usage

Fixtures

Fixtures declare exports that should be measured by the bundle-size tool. Fixtures are created inside each package.

For example:

import { Component } from '@fluentui/react-component';

console.log(Component);
// šŸ‘† "console.log()" is the easiest way to prevent tree-shaking

export default {
  name: 'Component',
  // šŸ‘† defines a name for story that will be used in output
};

Configuration

For custom advanced behavior of bundle-size, you can create a bundle-size.config.js in the root of your project directory (next to package.json).

my-proj/
ā”œā”€ src/
ā”œā”€ bundle-size.config.js
ā”œā”€ node_modules/
ā”œā”€ bundle-size/
ā”‚  ā”œā”€ Fixture.fixture.js
ā”œā”€ package.json

A global configuration can also be used for monorepo scenarios

my-proj-a/
ā”œā”€ src/
ā”œā”€ node_modules/
ā”œā”€ bundle-size/
ā”‚  ā”œā”€ Fixture.fixture.js
ā”œā”€ package.json
my-proj-b/
ā”œā”€ src/
ā”œā”€ node_modules/
ā”œā”€ bundle-size/
ā”‚  ā”œā”€ Fixture.fixture.js
ā”œā”€ package.json
bundle-size.config.js

Config API

module.exports = {
  webpack: config => {
    // customize config here
    return config;
  },
};

Commands

compare-reports

Compares local (requires call of bundle-size measure first) and remote results, provides output to CLI or to a Markdown file.

yarn bundle-size compare-reports --branch=main --output=["cli"|"markdown"] [--quiet]

measure

yarn bundle-size measure [--quiet]

Builds fixtures and produces artifacts. For each fixture:

  • [fixture].fixture.js - a modified fixture without a default export, used by a bundler
  • [fixture].output.js - a partially minified file, useful for debugging
  • [fixture].min.js - a fully minified file, used for measurements

A report file bundle-size.json that is used by other steps.

upload-report

yarn bundle-size upload-report --branch=main --commit-sha=HASH [--quiet]

Aggregates local results to a single report and uploads data to Azure Table Storage.

NOTE: should be called only during CI builds.