5

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

3
  • 1
    I have the same question. Did you find any solution? Commented Oct 5, 2018 at 15:37
  • any solution ?? Commented Jun 25, 2020 at 9:19
  • Does this help - blog.angular.io/… Commented Aug 11, 2021 at 5:10

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

I'm having a hard time finding your linked repository, was it deleted?
Ah, sorry, forgot I had that linked here. I got rid of it because it is out-of-date (Angular 7) and I switched not too long after this to a mono-repo using nx and I won't look back. It has saved me so much time. But I found the code on my laptop so I resurrected the repo. Hope it helps some but I don't know that I could answer any questions about it anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.