This repository shows a migration path from plain old AngularJS (scripts & bower) to
- AngularJS in ES6
- AngularJS in ES6 + VueJS (custom webpack)
- AngularJS in ES6 + VueJS (with @vue/cli)
- AngularJS in ES6 + React (custom webpack)
- AngularJS in ES6 + React (with create-create-app)
- AngularJS in Typescript (custom webpack)
- AngularJS in Typescript + Angular (with @angular/cli & @angular/upgrade)
Orginal code examples adapted from : https://github.com/pranavkotecha88/F1-feeder/
A hybrid, combining AngularJS with Angular, React or Vuejs, into a single app is possible but requires good knowledge of both frameworks. If you just starting to learn the new framework you will have a hard time ahead of you.
- You need knowledge of the internals of both frameworks. How are they conflicting and how are they working together.
- When things go wrong it's not always clear where the problem is located. You get a mix of AngularJS and Angular/React/VueJS errors. This can lead to confusion.
- You will have double implementations of some services or utilities. For example you can't re-use a pipe (or filter) in AngularJS vs Angular. You will have to maintain them both.
- If the couping of components is so high that changes to a single component cannot be isolated from other components it will be hard to migrate without a big re-write.
- There is litte, no and incorrect documentation/support available to make multiple frameworks work together. Your have to figure it out yourself.
-
To re-write the app completely. He, you can still re-use the following
- Html templates
- Styling (CSS)
- Rest API
- Functional requirement
- (optional) Universal javascript code
- (optional) Build and continious integration
- (optional) Deployment
-
To split your app in multiple smaller apps and create the new app's in the new framework
- Share data between apps via session/local storage and/or cookies.
-
How long are your going to support the old framework? Be carefull that your don't keep the old framework forever.
-
Which team will do the migration? Developers usually prefer to work on green field projects. You should take that into account when planning who will maintain the legacy version and who will work on the new one.
And finally consider to maybe not to migrate at all. AngularJS will still be supported for a long time. You can modernize your developer setup (webpack, typescript, npm, components, etc) but keep AngularJS for your exiting application.
If you still want to have an incremental migration these are the steps to take.
-
Stop with bower
-
Start with npm & webpack
-
Avoid gulp/grunt in favor of npm scripts
-
Upgrade to the latest version of AngularJS
-
Migrate script tags to ESM (ES Modules)
- Create ES Modules
- No more IIFE and 'use strict'
- Use Import/Export
- Use Javascript bundler (Webpack)
-
Migrate your javascript (improve your code)
- Prefer ES6+ language features
- Prefer to write universal javascript (platform independent)
- Prefer to follow the AngularJS Styleguide
- Prefer to follow a JavaScript styleguide (AirBnb, Standard, ...)
- Prefer AngularJS components (AngularJS v1.5+)
- Prefer Linter (Eslint) & code formatter (Prettier)
-
Migrate to Typescript (optional for VueJS)
-
Migrate to @Angular/CLI
- Start with a standard AngularCLI
- Add/cleanup your favor test setup (Jest, Karma, E2E)
- Add @angular/upgrade
- Add AnguarJS and move the old app into the new files structure
- Separate common code (services, pipes/filters)
-
Or Migrate to @vue/cli
- Start with a standard Vue CLI
- Add NgVue
- Add AnguarJS and move the old app into the new files structure
- Separate common code (services, filters)
-
Or Migrate to React
- Start with create-react-app or build your own webpack setup
- Add react2angular
- Add AnguarJS and move the old app into the new files structure
- Separate common code (services)
-
Prefer to separate your AngularJS and VueJS/Angular/React code as much as possible. The router is a good base to make this separation.
-
Prefer to write framework independent code. This code can be shared by both frameworks
-
Write new feature in the new framework
-
When an AngularJS feature changes, re-write it in the new framework
-
When all is migrated to remove AngularJS completely
When considering Angular, React or VueJS here some point to take into account:
-
All frameworks are here to stay.
-
Performance is not the issue anymore.
-
Good support and documentation is available for all.
-
Many open source and commercial libraries available for all.
-
Angular is more complete and powerfull but has added complexity:
- It's an opinionated framework: the Angular way
- Higher and long learning curve
- Typescript and typing
- RXJS and the world of observables
- Complex/slower bundeling and AOT compilation
- Dependency Injection
- Less univeral javascript code
- Change detection and zones is hard.
- ES Modules vs Angular modules
-
VueJS is easy to start with:
- Simple learning curve
- Vue is really fast
- More javascript code: objects (classes are also supported)
- Close to AngularJS template syntax
- More freedom to choose:
- ES5 vs ES6 vs TypeScript
- Callbacks, promises or observables
- Fetch, Axios, custom http service
- Easy out of the box support for flux pattern (vuex)
- Can be used without webpack and runs with ES5
- Simple change tracking
- No dependency injection
- Lightweight (smaller bundles, faster dev cycle)
- Faster and easier to unit test
- Average Typescript support
-
React is all aboute pure javascript:
- Initial high learning curve but gets easier once you know jsx & redux
- More ES6+ constructions & patterns (more functional approach)
- More freedom to choose:
- ES5, ES6, Flow vs TypeScript
- Callbacks, promises or observables
- Fetch, Axios, custom http service
- Works best with flux pattern (redux/modx)
- Simple change tracking
- No dependency injection
- Lightweight (smaller bundles, fastest dev cycle)
- Faster and easier to unit test
- Full support for hot reloading (css & code)
- Full Typescript support
Bundle Sizes/ Build time (prod)
AngularJS | Angular | VueJS | React | |
---|---|---|---|---|
Size | 200k | 620k | 334k | 118k |
Build Time | 7sec | 27sec | 16sec | 7sec |
Serve | 7sec | 17sec | 8sec | 6sec |
Different but equal (template syntax)
Angular | VueJS | AngularJS |
---|---|---|
[attr]="value" | :attr="value" | n/a |
(click)="onClick()" | @click="onClick()" | ng-click="onClick()" |
(mousemove)="onMove()" | @mousemove="onMove()" | n/a |
{{name}} | {{name}} | {{name}} |
[innerHtml]="rawHtml" | v-html="rawHtml" | ng-bind-html="rawHtml" |
*ngFor="let item of items" | v-for="item in items" | ng-repeat="item in items" |
*ngIf="condition" | v-if="condition" | ng-if="condition" |
[hidden]="!condition" | v-show="condition" | ng-show="condition" |
{{ message | uppercase }} | {{ message | uppercase}} | {{ message | uppercase}} |
{{ msg | upper:5 }} | {{ msg | upper(5)}} | {{ msg | upper:5}} |
([ngModel])="name" | v-model="name" | ng-model="name" |
- John Papa: A Look at Angular Alongside Vue - File Structure
- The State of JavaScript 2017
- Angular vs. React vs. Vue: A 2017 comparison
- Vue.js: the good, the meh, and the ugly
- LogLevel - Logger
- Axios - Http Client
- ngVue - AngularJS VueJS helper
- react2angular - AngularJS react helper
- A tiny, fast, zero-dependency event emitter
- Using AngularJS with ES6 and Webpack
- How to: Modernized AngularJS 1.5+
- AngularJS 1.5 with webpack, babel, and Jest
- Book - Upgrading Angular Applications
- Upgrading Angular Applications series (based on the book)
- Youtube - From Controllers to Components: Migrating to Angular 2
- GitHub - Demonstrating how to upgrade/migrate Angular 1 apps to Angular 2
- Converting an AngularJS 1.5 app to Angular 4
- Pluralsight - Preparing for Migration from AngularJS (1.x) to Angular (2+)
- Why and How We Migrated from AngularJS to VueJS
- GitHub - Use Vue2 components in Angular 1.x - NgVue
- GitHub - Sample project to show how to use Vue 2.0 components within AngularJS app
- How to Migrate from AngularJS to Vue – DailyJS – Medium
- Migrating to VueJS — Another way – Lucas Katayama
- How to embed Vue.js & Vuex inside an AngularJS app… wait what? - Cushion
- Progressively migrating from AngularJS to Vue.js at Unbabel