简体   繁体   中英

How to publish a library inside library to NPM within one workspace (singlerepo) nx nrwl

I have a workspace that includes one app in the apps/sandbox folder and two libraries in libs folder.

I have these two libs:
@workspace/library library and @angular/nrwl to NPM

  1. libs/ui
  2. libs/cdk-ui

I need to publish ui library to NPM but it's uses the cdk-ui and I would like to publish only one and not both libraries as NPM deps.

How it would be possible to accomplish? I would like that after I type 'npm install @ccc/ui' both of the libraries to work as usual without any separate publishing.

If any additional explanations would be needed please tell.

UPD: I have encountered on this: https://github.com/nrwl/nx/issues/225#issuecomment-373668866

But it's lack of good explanations on how to do it. Does anyone actually did it?

You can extend your npm publish command by writing a custom script on your UI lib's package.json that runs the cdk/ui library build at the end of your ui build command which then copy your build library with "cpx" inside the first one.

And to achieve that they end up in same place and directory, you'll have to change the tsconfig.lib.json of "cdk/ui": specifically outDir of your cdk/ui (which should match the other one)

So basically in your UI's package.json you have something like this:

{
    "build-library": "ng build ui  && npm run build-cdk-ui",
    "publish": "npm run build-library && npm run publish-dist",
    "build-cdk-ui": "tsc -p yourFolderForCDK-ui/tsconfig.lib.json && cpx your-resulted-dist dist/the-dist-you-want-to-put"
}

which triggers ng build for UI (which creates a dist folder), and after that you do ng build cdk/ui, which puts that dist inside other dist folder with cpx library that you should install and then you publish that folder.

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