角度服务库 [英] Angular serve library

查看:23
本文介绍了角度服务库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最新版本的 Angular cli 中,我们可以使用 ng g library lib-name 命令来创建库.如 Angular docs 中所述:

In latest versions of Angular cli, we can use ng g library lib-name command to create library. As mentioned in the Angular docs :

ng serve <project>

还有:

<project>   The name of the project to build. Can be an app or a library.

因此,我们可以为图书馆提供服务.但是当我发球时出现以下错误:

So, we can serve library. But when I serve I get the following errors:

Project 'ngx-tab-component' does not support the 'serve' target.
Error: Project 'ngx-tab-component' does not support the 'serve' target.
at ServeCommand.initialize (C:\Users\vahidnajafi\angular\ngx-tab-app\node_modules\@angular\cli\models\architect-command.js:53:19)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3

推荐答案

您在其中生成库的项目用作调试和测试它的主机.

The project where you generate your library in serves as a host to debug and test it.

只需在主机应用程序模块中导入您的库,确保所有依赖项都可用并为主机应用程序提供服务.您在库中所做的所有更改都会直接实时重新加载到您的主机应用程序中.

Simply import your library in your host application module, make sure all dependencies are available and serve the host application. All changes you make inside your library are directly live reloaded into your host application.

注意: 你必须导入projects/foo-lib/src/public_api,而不是'dist/foo-lib'

Note: You have to import projects/foo-lib/src/public_api, not 'dist/foo-lib' though

使用您的官方库名称,例如 @foo/foo-library,angular 会在正确的位置找到它.

Use your official library name, for example @foo/foo-library, angular will find it in the correct location.

这篇关于角度服务库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆