Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshwcomeau/tree-shake-test
https://github.com/joshwcomeau/tree-shake-test
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/joshwcomeau/tree-shake-test
- Owner: joshwcomeau
- Created: 2022-02-12T20:18:56.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-12T20:19:09.000Z (almost 3 years ago)
- Last Synced: 2024-12-09T14:14:44.454Z (24 days ago)
- Language: JavaScript
- Size: 146 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tree Shake Test
This repository was a quick test: I wanted to see if `import * as something from './file'` would affect tree-shaking, compared to specifying exactly which imports are necessary.
The good news: it doesn't matter! If you don't try to access an exported function, it will be trimmed out of the final bundle, no matter how you import it.
To reproduce the experiment:
1. Clone this repo
2. Install dependencies (`npm install`)
3. Build the codebase (`npm run build`)
4. Inspect the compiled code, in `build/static/js/main.6edac0cf.js`In the compiled code, you should be able to command-F / control-F and find the text `console.log("Function`.
If the tree shaking works, you should be able to find function 1:1 and function 2:1, since those functions are actually called. But you should _not_ be able to find 1:2 and 2:2.
You can see how the code is imported in `index.js`.