Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Size Limit [![Cult Of Martians][cult-img]][cult]\r\n\r\n<img align="right" width="120" height="178"\r\n title="Size Limit logo" src="./logo.svg">\r\n\r\nSize Limit is a tool to prevent JavaScript libraries bloat.\r\nWith it, you know exactly for how many kilobytes your JS library\r\nincreases the user bundle.\r\n\r\nYou can add Size Limit to your continuous integration service\r\n(such as Travis CI) and set the limit. If you accidentally\r\nadd a massive dependency, Size Limit will throw an error.\r\n\r\n<p align="center">\r\n <img src="./screenshots/example.png" alt="Size Limit example"\r\n width="654" height="450">\r\n
\r\n\r\nSize Limit could tell you not only library size. With--why
argument it can\r\ntell you why your library has this size and show real cost of all your\r\ninternal dependencies.\r\n\r\n<p align="center">\r\n <img src="./screenshots/why.png" alt="Bundle Analyzer example"\r\n width="650" height="335">\r\n\r\n\r\n<p align="center">\r\n <a href="https://evilmartians.com/?utm_source=size-limit\">\r\n <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg\"\r\n alt="Sponsored by Evil Martians" width="236" height="54">\r\n \r\n\r\n\r\n[Size Limit: Make the Web lighter]: https://evilmartians.com/chronicles/size-limit-make-the-web-lighter\r\n[cult-img]: http://cultofmartians.com/assets/badges/badge.svg\r\n[cult]: http://cultofmartians.com/tasks/size-limit-config.html\r\n\r\n## Who Uses Size Limit\r\n\r\n* MobX\r\n* Material-UI\r\n* Autoprefixer\r\n* PostCSS reduced\r\n 25% of the size.\r\n* Browserslist reduced\r\n 25% of the size.\r\n* EmojiMart reduced 20% of the size\r\n* nanoid reduced\r\n 33% of the size.\r\n* Logux reduced\r\n 90% of the size.\r\n\r\n\r\n## How It Works\r\n\r\nYou can find more examples in [Size Limit: Make the Web lighter] article.\r\n\r\nTo be really specific, Size Limit creates an empty webpack project in memory.\r\nThen, it adds your library as a dependency to the project and calculates\r\nthe real cost of your libraries, including all dependencies, webpack’s polyfills\r\nfor process, etc.\r\n\r\n\r\n## Usage\r\n\r\nFirst, installsize-limit
:\r\n\r\nsh\r\n$ npm install --save-dev size-limit\r\n
\r\n\r\nAddsize-limit
section topackage.json
andsize
script:\r\n\r\ndiff\r\n+ \"size-limit\": [\r\n+ {\r\n+ \"path\": \"index.js\"\r\n+ }\r\n+ ],\r\n \"scripts\": {\r\n+ \"size\": \"size-limit\",\r\n \"test\": \"jest && eslint .\"\r\n }\r\n
\r\n\r\nThepath
option:\r\n\r\n* For an open source library, specify compiled sources, which will be published\r\n to npm (usually the same value as themain
field in thepackage.json
);\r\n* For an application, specify a bundle file and usewebpack: false
(see the\r\n Applications section).\r\n\r\nHere’s how you can get the size for your current project:\r\n\r\nsh\r\n$ npm run size\r\n\r\n Package size: 8.46 KB\r\n With all dependencies, minified and gzipped\r\n\r\n
\r\n\r\nIf your project size starts to look bloated,\r\nrun Webpack Bundle Analyzer\r\nfor analysis:\r\n\r\nsh\r\n$ npm run size -- --why\r\n
\r\n\r\nNow, let’s set the limit. Determine the current size of your library,\r\nadd just a little bit (a kilobyte, maybe) and use that as a limit in\r\nyourpackage.json
:\r\n\r\ndiff\r\n \"size-limit\": [\r\n {\r\n+ \"limit\": \"9 KB\",\r\n \"path\": \"index.js\"\r\n }\r\n ],\r\n
\r\n\r\nAdd thesize
script to your test suite:\r\n\r\ndiff\r\n \"scripts\": {\r\n \"size\": \"size-limit\",\r\n- \"test\": \"jest && eslint .\"\r\n+ \"test\": \"jest && eslint . && npm run size\"\r\n }\r\n
\r\n\r\nIf you don’t have a continuous integration service running, don’t forget\r\nto add one — start with Travis CI.\r\n\r\n\r\n## Config\r\n\r\nSize Limits supports 3 ways to define config.\r\n\r\n1.size-limit
section topackage.json
:\r\n\r\njson\r\n \"size-limit\": [\r\n {\r\n \"path\": \"index.js\",\r\n \"limit\": \"9 KB\"\r\n }\r\n ]\r\n
\r\n\r\n2. or separated.size-limit
config file:\r\n\r\njs\r\n [\r\n {\r\n path: \"index.js\",\r\n limit: \"9 KB\"\r\n }\r\n ]\r\n
\r\n\r\n3. or more flexible.size-limit.js
config file:\r\n\r\njs\r\n module.exports = [\r\n {\r\n path: \"index.js\",\r\n limit: \"9 KB\"\r\n }\r\n ]\r\n
\r\n\r\nEach section in config could have options:\r\n\r\n* path: relative paths to files. The only mandatory option.\r\n It could be a path\"index.js\"
, a pattern\"dist/app-*.js\"
\r\n or an array[\"index.js\", \"dist/app-*.js\"]
.\r\n* limit: size limit for files frompath
option. It should be a string\r\n with a number and unit (100 B
,10 KB
, etc).\r\n* name: the name of this section. It will be useful only\r\n if you have multiple sections.\r\n* webpack: withfalse
will disable webpack.\r\n* gzip: withfalse
will disable gzip compression.\r\n* config: a path to custom webpack config.\r\n\r\n\r\n## Applications\r\n\r\nWebpack inside Size Limit is very useful for small open source library.\r\nBut if you want to use Size Limit for application, not open source library, you\r\ncould already have webpack to make bundle.\r\n\r\nIn this case you can disable internal webpack:\r\n\r\ndiff\r\n \"size-limit\": [\r\n {\r\n \"limit\": \"300 KB\",\r\n+ \"webpack\": false,\r\n \"path\": \"public/app-*.js\"\r\n }\r\n ],\r\n
\r\n\r\n\r\n## JavaScript API\r\n\r\njs\r\nconst getSize = require('size-limit')\r\n\r\nconst index = path.join(__dirname, 'index.js')\r\nconst extra = path.join(__dirname, 'extra.js')\r\n\r\ngetSize([index, extra]).then(size => {\r\n if (size.gzip > 1 * 1024 * 1024) {\r\n console.error('Project is now larger than 1MB!')\r\n }\r\n})\r\n
\r\n\r\n\r\n## Comparison withbundlesize
\r\n\r\nMain difference between Size Limit andbundlesize
, that Size Limit uses\r\nwebpack to build bundle. It has more accurate result and can show you\r\n_what_ and why causes the bloat.\r\n\r\n1. Size Limit has the--why
mode to run Webpack Bundle Analyzer — this way,\r\n you can see what went wrong in a nice graphical representation.\r\n2. Instead of bundlesize, Size Limit prevents the most popular source\r\n of libraries bloat — unexpected huge dependency.\r\n3. Also Size Limit prevents increasing library size because of wrongprocess
\r\n orpath
usage, when webpack will add big unnecessary polyfill.\r\n4. Size Limit runs only on first CI job, so it is more respectful\r\n to CI resources.