Skip to content

Create test #13

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

Merged
merged 1 commit into from
May 23, 2018
Merged

Create test #13

merged 1 commit into from
May 23, 2018

Conversation

luanapp
Copy link
Owner

@luanapp luanapp commented May 23, 2018

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, install size-limit:\r\n\r\nsh\r\n$ npm install --save-dev size-limit\r\n\r\n\r\nAdd size-limit section to package.json and size 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\nThe path 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 the main field in the package.json);\r\n* For an application, specify a bundle file and use webpack: 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\nyour package.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 the size 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 to package.json:\r\n\r\n json\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\n js\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\n js\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 from path 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: with false will disable webpack.\r\n* gzip: with false 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 with bundlesize\r\n\r\nMain difference between Size Limit and bundlesize, 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 wrong process\r\n or path 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.

@luanapp luanapp merged commit 9170132 into master May 23, 2018
@luanapp luanapp deleted the test branch May 23, 2018 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant