Skip to content

Angular 2 AOT (Ahead Of Time) offline compilation example with Webpack

Notifications You must be signed in to change notification settings

jbalbes/angular2-aot-webpack

 
 

Repository files navigation

Angular 2 AOT (Ahead Of Time) offline compilation example with Webpack

devDependency Status

This repository shows how to use the Angular 2 (RC6) command line offline compiler (ngc) with Webpack.

The application consists of a simple component(app/hello-world.component.ts) and a module(app/main.ts) which is bootstrapped.

When the application starts(npm start or npm run start-prod for production) it generates the compiled files next to the module and the component(*.ngfactory.ts),

There is a different entry point for the non compiled(app/bootstrap.ts) and AOT compiled application(bootstrap.aot.ts).

The difference between the development and production version is minification with UglifyJS. Both development and production builds create the AOT compiled files.

The application is bundled with Webpack from the bootstrap files and is available on http://localhost:9000. You can change between the different builds with commenting/uncommenting entry files from index.html.

Known issues

Templates must be inlined to the components. If not, a preprocessor is needed for inlining them, because otherwise the compiler can not determine what is needed in the templates.

Tree-shaking not included in this example, because tree-shaking only works with Typescript 2.0-dev+ and the packages needed for offline compilation have a strict dependency on 1.9-dev. Tried it with Typescript 2.0-dev, it works, but npm install complains about unmet dependencies and quits with error code.

If you wanna see Typescript tree-shaking check out this repository.

Instructions

npm i
npm start

About

Angular 2 AOT (Ahead Of Time) offline compilation example with Webpack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 44.3%
  • HTML 28.5%
  • TypeScript 27.2%