https://github.com/iggredible/tree-shake
Checks whether an NPM project is 100% tree-shakeable or not
https://github.com/iggredible/tree-shake
Last synced: 4 months ago
JSON representation
Checks whether an NPM project is 100% tree-shakeable or not
- Host: GitHub
- URL: https://github.com/iggredible/tree-shake
- Owner: iggredible
- Created: 2019-06-28T22:29:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-15T12:01:41.000Z (almost 6 years ago)
- Last Synced: 2024-04-24T16:04:47.452Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 363 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tree-shake
_Inspired by [agadoo](https://github.com/Rich-Harris/agadoo) lib_
Is your project 100% tree-shakeable?
With treeshake, you can find out which files and code lines that are not tree-shakeable.
## Usage
Simply run `npx treeshake` in your project root. **Make sure** you have your entry point defined in `package.json` under either `"module"` or `"main"`.
Upon running, you'll get notification whether your code is 100% tree-shakeable or not. If not, it will tell which file(s) are causing/ affected by side-effects and the codes that caused it.
```
********** reading files **********tree88shakey
TREESHAKEtRe eSha
kETREESHaKetreeshAKE
TreeShakEY o0o tREeSHAKE
Es6 /T r eesHakeY
\/// /Thanks
\//////
|||||
|||||
|||||
.....//||||\....
Awesome! Your code is 100% tree-shakeable!
```or
```
********** reading files **********
Unshaken files:/path/to/your/file.js
/another/path/to/your/file.js
********** reading codes **********
Unshaken codes:
console.log("Side-effects");********** Finished Reading **********
```## How do I make my project tree-shakeable?
1. Use ES6's [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
2. As much as possible, not have [side-effects](https://stackoverflow.com/questions/8129105/javascript-closures-and-side-effects-in-plain-english-separately)### More resources on JS modules
- [Dead code elimination vs tree shaking](https://medium.com/@Rich_Harris/tree-shaking-versus-dead-code-elimination-d3765df85c80#.jnypozs9n)
- [Anatomy of JS module systems](https://www.freecodecamp.org/news/anatomy-of-js-module-systems-and-building-libraries-fadcd8dbd0e/)
- [JS module system](https://github.com/kamleshchandnani/js-module-system)
- [RollupJS](https://rollupjs.org/guide/en/)
- [ESM](https://github.com/standard-things/esm)
- [ESM usage](https://hackernoon.com/7-different-ways-to-use-es-modules-today-fc552254ebf4)
- [ESM cartoon](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/)
- [Why you should use ESM](https://dev.to/bennypowers/you-should-be-using-esm-kn3)
- [Does node run all code inside required modules?](https://stackoverflow.com/questions/40464552/does-node-run-all-the-code-inside-required-modules)
Please feel free to ask any question/ submit PR!