This is a simple example on how to achieve tree shaking with Webpack 2. Don't use the project structure as a skeleton for your project. This repo only demonstrates how to achieve simple tree-shaking with Webpack 2 and TypeScript. You could use my fork of angular2-webpack-starter as a starter skeleton (as I have added, AOT and tree-shaking).
npm install
npm start
http://localhost:3000/
npm install
npm run build
Open dist/
- Webpack version has to be 2 or above (Webpack marks unused imports)
- The
compoiledOptions
section of tsconfig.json needs to be updated; changemodule
to 'es6' andmoduleResolution
to 'node` - UglifyJS will remove the unused imports