Skip to content

Commit 8b08552

Browse files
layershifterHotell
andauthored
chore: new bundle size tool (#18010)
* chore: new bundle size tool * fix NX workspace * fix permissions * disable version output * update readme * rename "build" script to "type-check" * rename "build" command to "measure", use "quiet" as a flag * remove ts-check pragma * use tsconfig.base.json and move "--noEmit" to config * rename to "@fluentui/bundle-size" and move to packages * restore fmt * type command export * type yarns init * remove usage of fs-extra, use SVP for del * do not mutate results * move schema to .json file * Update packages/bundle-size/README.md Co-authored-by: Martin Hochel <martinhochel@microsoft.com> * Update packages/bundle-size/README.md Co-authored-by: Martin Hochel <martinhochel@microsoft.com> * update structure of README Co-authored-by: Martin Hochel <martinhochel@microsoft.com>
1 parent d2504c7 commit 8b08552

28 files changed

+531
-47
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "add bundle size fixtures",
4+
"packageName": "@fluentui/react-divider",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "none"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "add bundle size fixtures",
4+
"packageName": "@fluentui/react-image",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "none"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "add bundle size fixtures",
4+
"packageName": "@fluentui/react-make-styles",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "none"
7+
}

nx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@fluentui/api-docs": { "implicitDependencies": [] },
3636
"@fluentui/azure-themes": { "implicitDependencies": [] },
3737
"@fluentui/babel-make-styles": { "implicitDependencies": [] },
38+
"@fluentui/bundle-size": { "implicitDependencies": [] },
3839
"@fluentui/codemods": { "implicitDependencies": [] },
3940
"@fluentui/common-styles": { "implicitDependencies": [] },
4041
"@fluentui/cra-template": { "implicitDependencies": [] },

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"vrtest": "cd apps && cd vr-tests && yarn screener"
7373
},
7474
"devDependencies": {
75+
"@babel/core": "7.12.16",
7576
"@ctrl/tinycolor": "3.3.4",
7677
"@microsoft/api-extractor": "7.13.0",
7778
"@nrwl/cli": "12.1.0",
@@ -102,19 +103,24 @@
102103
"@types/webpack-dev-middleware": "4.1.0",
103104
"@types/webpack-env": "1.16.0",
104105
"@types/yargs": "13.0.11",
106+
"ajv": "8.4.0",
105107
"babel-plugin-annotate-pure-calls": "0.4.0",
106108
"beachball": "1.53.1",
107109
"chalk": "4.1.0",
110+
"cli-table3": "0.6.0",
108111
"copy-webpack-plugin": "8.1.0",
109112
"cross-env": "^5.1.4",
110113
"css-loader": "5.0.1",
111114
"cypress": "6.6.0",
112115
"cypress-real-events": "1.2.0",
113116
"danger": "^6.0.5",
117+
"del": "6.0.0",
114118
"eslint": "7.25.0",
115119
"eslint-plugin-es": "4.1.0",
116120
"file-loader": "6.2.0",
121+
"glob": "7.1.6",
117122
"gulp": "^4.0.2",
123+
"gzip-size": "6.0.0",
118124
"html-webpack-plugin": "5.1.0",
119125
"imports-loader": "1.2.0",
120126
"jest": "24.9.0",
@@ -130,13 +136,15 @@
130136
"postcss-loader": "4.1.0",
131137
"postcss-modules": "2.0.0",
132138
"prettier": "2.2.1",
139+
"pretty-bytes": "5.6.0",
133140
"raw-loader": "4.0.2",
134141
"react-app-polyfill": "2.0.0",
135142
"sass-loader": "10.1.1",
136143
"satisfied": "^1.1.1",
137144
"storybook-addon-performance": "0.14.0",
138145
"style-loader": "2.0.0",
139146
"syncpack": "^5.6.10",
147+
"terser": "5.5.1",
140148
"tmp": "0.2.1",
141149
"ts-jest": "24.3.0",
142150
"ts-loader": "8.0.14",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["plugin:@fluentui/eslint-plugin/node"],
3+
"root": true,
4+
"rules": {
5+
"import/no-extraneous-dependencies": "off"
6+
}
7+
}

packages/bundle-size/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## `@fluentui/bundle-size`
2+
3+
A CLI tool to measure bundle size locally and on CI.
4+
5+
> NOTE: `bundle-size` requires to build packages first before doing any kind of measurements. Make sure to accommodate this in your pipeline\*\*
6+
7+
### Usage
8+
9+
#### Fixtures
10+
11+
Fixtures declare exports that should be measured by the `bundle-size` tool. Fixtures are created inside each package.
12+
13+
For example:
14+
15+
```js
16+
import { Component } from '@fluentui/react-component';
17+
18+
console.log(Component);
19+
// 👆 "console.log()" is the easiest way to prevent tree-shaking
20+
21+
export default {
22+
name: 'Component',
23+
// 👆 defines a name for story that will be used in output
24+
};
25+
```
26+
27+
### Commands
28+
29+
#### `measure`
30+
31+
```sh
32+
yarn bundle-size measure [--verbose]
33+
```
34+
35+
Builds fixtures and produces artifacts.
36+
37+
For each fixture:
38+
39+
- `[fixture].fixture.js` - a modified fixture without a default export, used by a bundler
40+
- `[fixture].output.js` - a partially minified file, useful for debugging
41+
- `[fixture].min.js` - a fully minified file, used for measurements
42+
43+
A report file `bundle-size.json` that is used by other steps.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('../src/index');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { preset } from '@fluentui/scripts';
2+
3+
preset();

packages/bundle-size/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@fluentui/bundle-size",
3+
"version": "1.0.0",
4+
"private": true,
5+
"bin": {
6+
"bundle-size": "./bin/bundle-size.js"
7+
},
8+
"scripts": {
9+
"lint": "just-scripts lint",
10+
"type-check": "tsc"
11+
}
12+
}

0 commit comments

Comments
 (0)