Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix size units #219

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ interactive elements, using React/Vue/Svelte lib or vanilla JS.
```sh
$ npm run size

Package size: 30.08 KB with all dependencies, minified and gzipped
Package size: 30.08 kB with all dependencies, minified and gzipped
```

4. Now, let’s set the limit. Add 25% to the current total time and use that as
Expand All @@ -134,7 +134,7 @@ interactive elements, using React/Vue/Svelte lib or vanilla JS.
```diff
"size-limit": [
{
+ "limit": "35 KB",
+ "limit": "35 kB",
"path": "dist/app-*.js"
}
],
Expand All @@ -159,10 +159,10 @@ interactive elements, using React/Vue/Svelte lib or vanilla JS.

### JS Application and Time-based Limit

File size limit (in KB) is not the best way to describe your JS application
File size limit (in kB) is not the best way to describe your JS application
cost for developers. Developers will compare the size of the JS bundle
with the size of images. But browsers need much more time to parse 100 KB
of JS than 100 KB of an image since JS compilers are very complex.
with the size of images. But browsers need much more time to parse 100 kB
of JS than 100 kB of an image since JS compilers are very complex.

This is why Size Limit support time-based limit. It runs headless Chrome
to track the time a browser takes to compile and execute your JS.
Expand Down Expand Up @@ -195,7 +195,7 @@ to track the time a browser takes to compile and execute your JS.
```sh
$ npm run size

Package size: 30.08 KB with all dependencies, minified and gzipped
Package size: 30.08 kB with all dependencies, minified and gzipped
Loading time: 602 ms on slow 3G
Running time: 214 ms on Snapdragon 410
Total time: 815 ms
Expand Down Expand Up @@ -232,10 +232,10 @@ to track the time a browser takes to compile and execute your JS.

### Big Libraries

JS libraries > 10 KB in size.
JS libraries > 10 kB in size.

This preset includes headless Chrome, and will measure your lib’s execution
time. You likely don’t need this overhead for a small 2 KB lib, but for larger
time. You likely don’t need this overhead for a small 2 kB lib, but for larger
ones the execution time is a more accurate and understandable metric that
the size in bytes. Library like [React] is a good example for this preset.

Expand Down Expand Up @@ -279,7 +279,7 @@ the size in bytes. Library like [React] is a good example for this preset.
```sh
$ npm run size

Package size: 30.08 KB with all dependencies, minified and gzipped
Package size: 30.08 kB with all dependencies, minified and gzipped
Loading time: 602 ms on slow 3G
Running time: 214 ms on Snapdragon 410
Total time: 815 ms
Expand Down Expand Up @@ -318,7 +318,7 @@ the size in bytes. Library like [React] is a good example for this preset.
Short project description

* **Fast.** 10% faster than competitor.
+ * **Small.** 15 KB (minified and gzipped).
+ * **Small.** 15 kB (minified and gzipped).
+ [Size Limit](https://github.com/ai/size-limit) controls the size.
```

Expand All @@ -327,7 +327,7 @@ the size in bytes. Library like [React] is a good example for this preset.

### Small Libraries

JS libraries < 10 KB in size.
JS libraries < 10 kB in size.

This preset will only measure the size, without the execution time, so it’s
suitable for small libraries. If your library is larger, you likely want
Expand Down Expand Up @@ -377,7 +377,7 @@ for this preset.
```diff
"size-limit": [
{
+ "limit": "9 KB",
+ "limit": "9 kB",
"path": "index.js"
}
],
Expand Down Expand Up @@ -492,7 +492,7 @@ Each section in the config can have these options:
to test multiple files.
* **limit**: size or time limit for files from the `path` option. It should be
a string with a number and unit, separated by a space.
Format: `100 B`, `10 KB`, `500 ms`, `1 s`.
Format: `100 B`, `10 kB`, `500 ms`, `1 s`.
* **name**: the name of the current section. It will only be useful
if you have multiple sections.
* **entry**: when using a custom webpack config, a webpack entry could be given.
Expand All @@ -508,7 +508,7 @@ Each section in the config can have these options:

If you use Size Limit to track the size of CSS files, make sure to set
`webpack: false`. Otherwise, you will get wrong numbers, because webpack
inserts `style-loader` runtime (≈2 KB) into the bundle.
inserts `style-loader` runtime (≈2 kB) into the bundle.

[pattern]: https://github.com/sindresorhus/globby#globbing-patterns

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"CI",
"gzip",
"js",
"KB",
"kB",
"nanoid",
"npm",
"Storeon",
Expand Down
2 changes: 1 addition & 1 deletion packages/preset-big-lib/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Size Limit Preset for Big Libraries

The preset for [Size Limit] for libraries > 10 KB. It uses
The preset for [Size Limit] for libraries > 10 kB. It uses
webpack, file and time plugins to track the time of JS download and execution
of library and all dependencies.

Expand Down
2 changes: 1 addition & 1 deletion packages/preset-small-lib/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Size Limit Preset for Small Libraries

The preset for [Size Limit] for libraries < 10 KB. It uses
The preset for [Size Limit] for libraries < 10 kB. It uses
webpack and file plugins to track the size of all files and dependencies.

See Size Limit docs for more details.
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/create-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = process => {
'For frameworks, components and big libraries',
' ' + y(add + '@size-limit/preset-big-lib'),
'',
'For small (< 10 KB) libraries',
'For small (< 10 kB) libraries',
' ' + y(add + '@size-limit/preset-small-lib'),
'',
'Check out docs for more complicated cases',
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/create-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let {
yellow
} = require('colorette')
let { join } = require('path')
let bytes = require('bytes')
let bytes = require('bytes-iec')

function createJsonReporter(process) {
function print(data) {
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/get-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let { isAbsolute, dirname, join, relative } = require('path')
let { lilconfig } = require('lilconfig')
let globby = require('globby')
let bytes = require('bytes')
let bytes = require('bytes-iec')

let SizeLimitError = require('./size-limit-error')

Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"node": "^10 || ^11 || ^12 || >=13.7"
},
"dependencies": {
"bytes": "^3.1.0",
"bytes-iec": "^3.1.1",
"chokidar": "^3.5.1",
"ci-job-number": "^1.2.2",
"colorette": "^1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/size-limit-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SizeLimitError extends Error {
' "size-limit": [\n' +
' {\n' +
' "path": "dist/bundle.js",\n' +
' "limit": "10 KB"\n' +
' "limit": "10 kB"\n' +
' }\n' +
' ]\n'
}
Expand Down
44 changes: 22 additions & 22 deletions packages/size-limit/test/__snapshots__/create-reporter.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
exports[`highlight passed results with --highlight-less flag 1`] = `
"
ok
Size limit: 100 KB
Size: 100 KB gzipped
Size limit: 102.4 kB
Size: 102.4 kB gzipped

good
Size limit: 100 KB
Size: 95 KB  gzipped
Size limit: 102.4 kB
Size: 97.28 kB gzipped

fail
Package size limit has exceeded by 1 B
Expand All @@ -28,8 +28,8 @@ exports[`only renders failed results with --hide-passed flag 1`] = `

big fail
Package size limit has exceeded by 100 B
Size limit: 100 KB
Size: 100.1 KB gzipped
Size limit: 102.4 kB
Size: 102.5 kB gzipped

Try to reduce size or increase limit in \\"size-limit\\" section of package.json
"
Expand Down Expand Up @@ -62,7 +62,7 @@ exports[`renders config-less result 1`] = `
"
Total time limit has exceeded
Time limit: 500 ms
Size: 1000 B
Size: 1 kB
Loading time: 200 ms on slow 3G
Running time: 300 ms on Snapdragon 410
Total time: 500 ms
Expand All @@ -74,8 +74,8 @@ exports[`renders config-less result 1`] = `
exports[`renders failed results 1`] = `
"
ok
Size limit: 100 KB
Size: 100 KB gzipped
Size limit: 102.4 kB
Size: 102.4 kB gzipped

small fail
Package size limit has exceeded by 1 B
Expand All @@ -84,8 +84,8 @@ exports[`renders failed results 1`] = `

big fail
Package size limit has exceeded by 100 B
Size limit: 100 KB
Size: 100.1 KB gzipped
Size limit: 102.4 kB
Size: 102.5 kB gzipped

Try to reduce size or increase limit in \\"size-limit\\" section of package.json
"
Expand All @@ -100,8 +100,8 @@ exports[`renders list of failed and success checks in silent mode 1`] = `

big fail
Package size limit has exceeded by 100 B
Size limit: 100 KB
Size: 100.1 KB with all dependencies, minified and gzipped
Size limit: 102.4 kB
Size: 102.5 kB with all dependencies, minified and gzipped

"
`;
Expand All @@ -115,8 +115,8 @@ exports[`renders list of failed checks in silent mode 1`] = `

big fail
Package size limit has exceeded by 100 B
Size limit: 100 KB
Size: 100.1 KB with all dependencies, minified and gzipped
Size limit: 102.4 kB
Size: 102.5 kB with all dependencies, minified and gzipped

"
`;
Expand All @@ -143,17 +143,17 @@ exports[`renders results 1`] = `
Total time: 600 ms

size
Size limit: 100 KB
Size: 100 KB with all dependencies, minified and gzipped
Loading time: 1 s  on slow 3G
Running time: 2 s  on Snapdragon 410
Size limit: 102.4 kB
Size: 102.4 kB with all dependencies, minified and gzipped
Loading time: 1 s  on slow 3G
Running time: 2 s  on Snapdragon 410
Total time: 3 s

time
Time limit: 4 s
Size: 100 KB with all dependencies and minified
Loading time: 1 s  on slow 3G
Running time: 2 s  on Snapdragon 410
Size: 102.4 kB with all dependencies and minified
Loading time: 1 s  on slow 3G
Running time: 2 s  on Snapdragon 410
Total time: 3 s

"
Expand Down
24 changes: 12 additions & 12 deletions packages/size-limit/test/__snapshots__/run.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

exports[`run allows to use peer dependencies in import 1`] = `
"
Size: 2.44 KB with all dependencies, minified and gzipped
Size: 2.5 kB with all dependencies, minified and gzipped

"
`;

exports[`run find plugins in parent package.json 1`] = `
"
Size limit: 1 KB
Size limit: 1 kB
Size: 20 B gzipped

"
Expand All @@ -33,7 +33,7 @@ exports[`run returns zero bytes for empty file without gzip 1`] = `

exports[`run shows brotli text when brotli and gzip in config 1`] = `
"
Size limit: 1 KB
Size limit: 1 kB
Size: -53 B with all dependencies, minified and brotli
Loading time: 10 ms on slow 3G
Running time: 1 s  on Snapdragon 410
Expand All @@ -44,7 +44,7 @@ exports[`run shows brotli text when brotli and gzip in config 1`] = `

exports[`run shows brotli text when only brotli in config 1`] = `
"
Size limit: 1 KB
Size limit: 1 kB
Size: -53 B with all dependencies, minified and brotli
Loading time: 10 ms on slow 3G
Running time: 1 s  on Snapdragon 410
Expand Down Expand Up @@ -275,7 +275,7 @@ For application, where you send JS bundle directly to users
For frameworks, components and big libraries
npm install --save-dev @size-limit/preset-big-lib

For small (< 10 KB) libraries
For small (< 10 kB) libraries
npm install --save-dev @size-limit/preset-small-lib

Check out docs for more complicated cases
Expand All @@ -292,7 +292,7 @@ For application, where you send JS bundle directly to users
For frameworks, components and big libraries
npm install --save-dev @size-limit/preset-big-lib

For small (< 10 KB) libraries
For small (< 10 kB) libraries
npm install --save-dev @size-limit/preset-small-lib

Check out docs for more complicated cases
Expand All @@ -311,7 +311,7 @@ For application, where you send JS bundle directly to users
For frameworks, components and big libraries
yarn add --dev @size-limit/preset-big-lib

For small (< 10 KB) libraries
For small (< 10 kB) libraries
yarn add --dev @size-limit/preset-small-lib

Check out docs for more complicated cases
Expand Down Expand Up @@ -388,7 +388,7 @@ exports[`run throws on empty config 1`] = `
\\"size-limit\\": [
{
\\"path\\": \\"dist/bundle.js\\",
\\"limit\\": \\"10 KB\\"
\\"limit\\": \\"10 kB\\"
}
]
"
Expand All @@ -405,7 +405,7 @@ exports[`run throws on no config 1`] = `
\\"size-limit\\": [
{
\\"path\\": \\"dist/bundle.js\\",
\\"limit\\": \\"10 KB\\"
\\"limit\\": \\"10 kB\\"
}
]
"
Expand All @@ -417,7 +417,7 @@ exports[`run throws on non-array config 1`] = `
\\"size-limit\\": [
{
\\"path\\": \\"dist/bundle.js\\",
\\"limit\\": \\"10 KB\\"
\\"limit\\": \\"10 kB\\"
}
]
"
Expand All @@ -429,7 +429,7 @@ exports[`run throws on non-object check 1`] = `
\\"size-limit\\": [
{
\\"path\\": \\"dist/bundle.js\\",
\\"limit\\": \\"10 KB\\"
\\"limit\\": \\"10 kB\\"
}
]
"
Expand All @@ -446,7 +446,7 @@ exports[`run throws on non-string path 1`] = `
\\"size-limit\\": [
{
\\"path\\": \\"dist/bundle.js\\",
\\"limit\\": \\"10 KB\\"
\\"limit\\": \\"10 kB\\"
}
]
"
Expand Down
2 changes: 1 addition & 1 deletion packages/size-limit/test/create-reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ it('highlight passed results with --highlight-less flag', () => {
},
{
name: 'good',
size: 97280, // 5 KB less
size: 97280, // 5 KiB less
sizeLimit: 102400,
passed: true
},
Expand Down
Loading