Nrwl Nx: Merging lib into a publishable lib

Viewed 443

I have a Nx workspace and want to build two npm packages: one for React and one for Angular. Both using some shared code.

The structure is like this:

  • lib
    • core
    • react-lib
    • angular-lib

If I make the core library publishable and want to publish angular-lib to npm I need to publish the core package as well, which I don't want.

If the core is not publishable I get the File xxx.ts is not under 'rootDir'

Does anyone know if its possible to create an angular-lib package with the used code of the data lib included?

Here the code

1 Answers

maybe git submodules is what you really need.

So if you do not want to pulish 'core', but want that module be reusable between react-lib and angular-lib. You just hook up repo of 'core' as a submodule to repos of 'react-lib' and 'angular-lib' and have file structure like as follows

core - has its own git repo

angular-lib - has its own git repo and 'core as submodule'.

./src

./core - git submodule

react-lib - has its own git repo and 'core as submodule'

./src

./core - git submodule

you can update entire angular-lib including subdirectory 'core' with single command 'git pull --recursive'

From angular's and react's point of view that 'core' is just a subdirectory, you can import source files from there etc. 'ng build' will include all neccessary into resulting bundle. So code from 'core' is reusable and updatable from git and no need to publish npm package for that.

Or - approach #2 - just use symlinks. Make symlink to directory of 'core' in directories of 'angular-lib' and 'react-lib'. And import source code from ./core. 'ng build' will create proper bundle - it will include copy of files, no symlynks.

Related