Gabriel Araujo
Gabriel Araujo

Reputation: 769

Can I have a mixed es5 / es2015 AngularJS app?

At my work, we have a large AngularJS app written with ES5 which is planned to migrate very soon. Before migration to any other JS framework (Angular 2+ or React) I would like to take a smaller step migrating the current app to ES2015. However, since it's a production large app, it would be more easy if we can handle this migration gradually.

I know there is a lot of tutorials about AngularJS with ES2015, but I failed to find any which address the situation with mixed ES5 and ES2015 files.

Furthermore, the current ES5 app uses lazy loaded routes with ocLazyload + ui-router, and I'm not sure how this will play with ES2015 module loaders like SystemJS or Webpack.

Any of guys know how to handle this particular scenario?

Thanks in advance.

Upvotes: 0

Views: 879

Answers (1)

Badacadabra
Badacadabra

Reputation: 8497

ES2015 is just pure JavaScript with a richer API and a lot of syntactic sugar. For example, when you use a class in ES6, this is not a new data structure in the language. This is just syntactic sugar that hide the prototypal nature of JavaScript. Behind the scenes, it is still a function.

So wen you develop an application, you can of course mix ES5 and ES6. If you compile your code with Babel or Traceur, you should have a valid output because ES5 is valid JavaScript.

As you may know, Angular 2 uses TypeScript. But TypeScript is not like CoffeeScript. This is not another language that compiles to JavaScript. Microsoft defines it as a superset of JavaScript. Indeed, if you take a minimal ES5 code and try to compile it with tsc, it will work.

So yes, you should be able to do the migration gradually. :)

Upvotes: 1

Related Questions