Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sonicoder86/typescript-webpack-tree-shaking
Tree-shaking example with Typescript and Webpack
https://github.com/sonicoder86/typescript-webpack-tree-shaking
babili tree-shaking typescript webpack
Last synced: about 1 month ago
JSON representation
Tree-shaking example with Typescript and Webpack
- Host: GitHub
- URL: https://github.com/sonicoder86/typescript-webpack-tree-shaking
- Owner: sonicoder86
- Created: 2016-08-21T13:18:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-17T06:11:07.000Z (over 7 years ago)
- Last Synced: 2024-02-23T12:28:43.536Z (10 months ago)
- Topics: babili, tree-shaking, typescript, webpack
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 145
- Watchers: 11
- Forks: 20
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Tree-shaking example with Typescript and Webpack
[![devDependency Status](https://david-dm.org/blacksonic/typescript-webpack-tree-shaking/dev-status.svg)](https://david-dm.org/blacksonic/typescript-webpack-tree-shaking?type=dev)This repository shows how to configure Typescript and Webpack to enable tree-shaking.
It will eliminate dead code if they have ES2015 module format.The source code can be found in the ```app/``` folder,
where the main file ```car.js``` doesn't use all the dependencies from ```engine.js```.
The built and transpiled files can be found in the ```/dist``` folder.Webpack only marks unused code at bundling and leaves the removing part to minifiers.
This is why all the code is included in development builds in contrary to Rollup.If you want a more detailed explanation,
[read this article](https://blog.craftlab.hu/how-to-do-proper-tree-shaking-in-webpack-2-e27852af8b21).### Webpack + Typescript + UglifyJS
Can only remove unused functions and variables.
For development build run ```npm run webpack``` (Typescript -> ES5 bundle).
For production build run ```npm run webpack-prod``` (Typescript -> ES5 bundle -> UglifyJS).
When transpiling classes with Typescript, it generates an IIFE with an assignment to the prototype.
It is considered as a side effect by UglifyJS and it skips removing of it.See the issues below:
- [Webpack issue](https://github.com/webpack/webpack/issues/2899) and a [more detailed one](https://github.com/webpack/webpack/issues/2867)
- [UglifyJS issue](https://github.com/mishoo/UglifyJS2/issues/1261)### Webpack + Typescript + Babili
Can remove unused classes, functions and variables.
For development build run ```npm run webpack-es2015``` (Typescript -> ES2015 bundle).
For production build run ```npm run webpack-es2015-prod``` (Typescript -> ES2015 bundle -> Babili).
It uses the [Babili](https://github.com/babel/babili) ES6+ aware minifier and solves the issues what UglifyJS has.