Janosch Hübner
Janosch Hübner

Reputation: 1694

npm local development vs production package versions

I am trying to use my own package (let's call it database) in a project of mine. However since I am developing database next to the project myself, I don't want to push a version of database to the registry, then pull again on the project to have the latest version. This is not a fast workflow given that both projects are in the same VS workspace.

What I need is to reference the local project while development and when it is about production, then I need to actually use an external package. Is there a way that allows me to use a different package version of the same package depending on the environment?

I wish there was a NodeJS / Typescript IDE that just manages packages, building dependencies etc. for me. E.g when I build my project, it would build database first. I know there are project references in typescript 3.0, however I am not sure how well they work with npm packages.

Thanks for any help.

Upvotes: 1

Views: 661

Answers (1)

sfy
sfy

Reputation: 3238

Go to your package database directory and run npm link to create a global symlink, it would be like you have installed the database globally.

Go to your project to run npm link database to use the local global package.

You don't need to update your project's dependency when you update the database since the global package is just a local symbol link to your database.

When you are ready to go production, run npm unlink database to remove the local symbol link, and reinstall the package from the registry for the project, you need to publish it first of course.

Upvotes: 2

Related Questions