I'm trying to migrate an Angular app to a shared codebase with Nativescript using the new @nativescript/schematics
, however, I'm having problems importing my Angular library when building the mobile version of the app. I used the angular-cli to create the library (ng generate library
).
For the web version, all I had to do was build the library separately using ng build library-name
which then allowed me to import it into the main application.
How can I build a mobile version of the library that can be imported into the main application when running tns run ios --bundle
? I've already migrated the components and module of the library with appropriate *.tns files.
Any help is appreciated
I had the same problem. Nativescript cli do not have this feature where we can build an angular library into npm package and use it in other projects.
I tried a workaround and it worked for me. Write a script to copy all of your project files into another directory and replace all *.tns.ts, *tns.html and *.tns.scss. files with *.ts, *.html and *.scss respectively. Then build these files using regular ng command. You can add a build configuration for the same in angular.json file to build from the copied directory. I hope it helps.
I'm sorry this is just a hyperlink answer but the space required to answer this, in my opinion, is way too large. I just finished finalizing a repo I've been working on to do exactly this. I have a whole slew of angular web libraries that I now want to make available for use on mobile using NativeScript. I have put everything I have learned so far into this repo and I hope it helps you too.
Thanks for the final push/idea @Rohit, a script for doing what he suggests is in the test-lib/gulpfile.js
of this repo.