NodeJS monorepo with non-npm project

83 Views Asked by At

Basically I'd like to know how to share code between nodejs projects. There is a module need to be used by multiple projects, lets call it shared module, the shared module has its own package.json and dependencies. at development I can use pnpm or typescript path alias to make it work, but I do not want to publish the shared module to the npm registry, so the question is how do I make it avaliable for these projects that use it as dependency which runs on server or published to users?

the code structure:

/packages
  /shared
    package.json
  /api-server // runs on server
    package.json
  /cool-cli  // published to NPM
    package.json

Currently I was use npm install ../shared to make it avaliable for api-server, but this makes me write a kind of complexity publish script and I don't know if its a workable way for NPM packages too, I may need to publish the cool-cli like this:

/dist
/shared
package.json
{
  ...
 dependencies: {
   "shared": "./shared"
 }
}

I also have another idea is to bundle the shared module to other projects' source code without a separate package.json, but this wont work for dependencies that can not bundle into js.

0

There are 0 best solutions below