Using Angular libraries in Nativescript code sharing project

时间秒杀一切 提交于 2019-12-23 19:55:02

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/52390655/using-angular-libraries-in-nativescript-code-sharing-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!