Angular2+typescript+webpack2 (AOT support, tree shaking, lazy loading)

Source: Internet
Author: User

Overview

ANGULAR2 's official recommendation should be to use SYSTEMJS to load, but when I use the tree shaking, I find that if I use Systemjs+rollup, I can only package it into one file, and then lazy loading can't do it.

So I used webpack2,webpack2 with the tree shaking, as long as the Tsconfig in the module set to es2015, although the effect is not rollup good, but support lazy loading.

In addition, ANGULAR2 currently does not support typescript 2.1.X, so if you want to use async/await on "target": "ES5", you can set target to es2015, then introduce Babel-loader, In this case, the packaged code will be a little bit larger.

Source

The GitHub address for the project is Https://github.com/nickppa/myAngular2Aot, the official hero example, without the introduction of Babel under the master branch, The Babel is introduced under the Webpack-babel branch to support Async/await.

Reference to Https://github.com/AngularClass/angular2-webpack-starter, not using HMR (unloading), looked at the HMR of the relevant code, a bit like the redux of the concept of a single state.

Spit Groove Typescriptinterface

Feel Typescript interface is a chicken, rather than all defined as class, the original is as follows

It's not a Angular ' s fault. An interface is a TypeScript design-time artifact. JavaScript doesn ' t has interfaces. The TypeScript interface disappears from the generated JavaScript. There is no interface type information left for Angular to find at runtime.

That is, when Typescript is converted to JavaScript, the interface is deleted.

function overloading

In addition, the Typescript function overload, the personal feeling this writing is too low.

Summarize

The feeling of typescript is mostly strongly typed, supported by various new grammars for ES6,ES7 (how to Feel Babel better), as well as generics and TSC compilation. Other advantages temporarily haven't found, say 2.1 in keyof pretty good, but angular2 inside now still can't use AH.

In addition, the project attempted to use the immutable, as well as the ANGULAR2 OnPush strategy.

Angular2+typescript+webpack2 (AOT support, tree shaking, lazy loading)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.