Ionic 2, Angular 2 Mobile App and Web App Same Codebase

After working with Ionic 2 in sample apps here and there and working with Angular 2 in the same capacity, I would really like to know if anyone has attempted to write one set of class components with views for Ionic and another set of views for a normal web app, transpiling each in one shot.

In other words, I’d like to have a single project, using different views: one set of views for Ionic and one set of views for a normal web app, and transpile (with TypeScript) each into their own directories. So, for Ionic, it would be the experience as it is now with V2 with the addition of another directory that includes a set of views (same class components) that are just for the web (Angular 2 views).

This is the ultimate dream of code reuse. I’m sure it’s possible to get the TypeScript compiler to output to 2 different directories using different templates, but I’m not sure how. Any input would be greatly appreciated.

Hi donniefitz,

I am looking to code reuse between Angular 2 Web and Ionic 2 APP. Did you solve it?

I never did find a solution to code reuse as I ended up going in a different direction. Sorry.

UPDATE: I read question incorrectly. I do use same views for both mobile and web apps. Sorry if misleaded.

Hi, I did just that for

While trying to make it working I’ve came to conclusion that it is better not to include cordova.js and do not use web implementations of various Cordova plugins (like Facebook for examle) as for web apps this approach works in sub-optimal way.

In my index.html I check location.protocol and if starts with “http” do not load Cordova.js. I had to port or implement myself plugins parts. For I dynamically load Fb SDK when needed and in the app I have my own wrapped that uses either Cordova plugin class or fb js sdk.