0

In my sample Angular 2 SPA , I have used Webpack 2 module bundler in order

  1. Bundle all my js files
  2. Implement "Tree Shaking" to remove dead code and reduce bundle js file size
  3. and to implement Ahead-of-time compilation to reduce the bundle js file size further.

I was able to achive "1" and "2" by creating a webpack.config.js file , and below are the contents of this file

'use strict';
const webpack = require('webpack');

module.exports = {
    devtool: 'source-map',
    entry: './src/main.js',
    plugins: [
    new webpack.optimize.UglifyJsPlugin({
        minimize: true,
        compress: false
    })
    ],
    output: {
        filename:'./src/bundle.js'
    }
}

Now what is that I need to do further , so that Ahead-of-time compilation can also be achieved ?

refactor
  • 13,954
  • 24
  • 68
  • 103
  • 1
    Possible resource: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html – R. Richards Feb 14 '17 at 13:01
  • You might be confusing *uglifying* (rewriting code to use short, cryptic variable and function names) and *tree-shaking* (discarding unused code). Angular.io recommends using [rollup for tree-shaking](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html#rollup) but it doesn't look like you're using it here. – AngularChef Feb 14 '17 at 13:34
  • After including "webpack.optimize.UglifyJsPlugin" , size of bundle did come down from 2.5 mb to 660 kb. – refactor Feb 14 '17 at 13:37

0 Answers0