角服务库 [英] Angular serve library

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

问题描述

在最新版本的Angular cli中,我们可以使用 ng g库lib-name 命令创建库。如Angular中所述文档

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天全站免登陆