简体   繁体   中英

Import Stencil JS library from another Stencil JS library

I have two libraries of Stencil JS web components, library-a and library-b. These are not apps, just separate npm packages of components.

I would like to use some of the components from library-a inside library-b. How do I import components from A into B?

The StencilJS docs offer some import instructions but don't cover this particular use case.

Basically all you have to do is npm install (or npm link ) the project and import it.

As far as I know there are two places you can include the import:

  1. Inside a global app.ts which is configured as a globalScript in stencil.config.ts .
  2. Inside the root component.

In your case the second option probably won't work since component libraries usually don't have a root component.

Import inside app.ts :

First, create a global script and configure it in your 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM