[英]Import Stencil JS library from another Stencil JS library
I have two libraries of Stencil JS web components, library-a and library-b.我有两个 Stencil JS web 组件库,library-a 和 library-b。 These are not apps, just separate npm packages of components.
这些不是应用程序,只是单独的 npm 组件包。
I would like to use some of the components from library-a inside library-b.我想在 library-b 中使用 library-a 中的一些组件。 How do I import components from A into B?
如何将组件从 A 导入 B?
The StencilJS docs offer some import instructions but don't cover this particular use case. StencilJS 文档提供了一些导入说明,但未涵盖此特定用例。
Basically all you have to do is npm install
(or npm link
) the project and import it.基本上你所要做的就是
npm install
(或npm link
)项目并导入它。
As far as I know there are two places you can include the import:据我所知,有两个地方可以包含导入:
app.ts
which is configured as a globalScript
in stencil.config.ts
.app.ts
中,它在stencil.config.ts
globalScript
In your case the second option probably won't work since component libraries usually don't have a root component.在您的情况下,第二个选项可能不起作用,因为组件库通常没有根组件。
Import inside app.ts
:在
app.ts
导入:
First, create a global script and configure it in your stencil.config.ts
:首先,创建一个全局脚本并在你的
stencil.config.ts
中配置它:
export const config: Config = {
// ...
globalScript: 'src/global/app.ts',
};
Then add the import inside that file.然后在该文件中添加导入。 Example for Ionic Framework:
离子框架的例子:
import '@ionic/core';
Now you can use the components just like any other HTML element.现在您可以像使用任何其他 HTML 元素一样使用这些组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.