This page looks best with JavaScript enabled

Use Packages Locally Without Publishing Them

 ·   ·  ☕ 2 min read

How can you use packages being developed locally in other projects - without publishing them to npm repository?

NPM Packages Make Life Exciting

NPM makes it really easy to create packages and reuse them across projects.

I am not even talking about big, useful libraries like Vue, Loadash etc. - just the routine problems across our projects.

For example -

  1. I use a module to validate a bunch of things and start user subscription for an app
  2. I use similar starter theme for sites across projects

It is easier to create NPM packages and reuse them instead of copying the code everywhere and starting the great struggle for its maintenance.

All we need to do is to go the project folder and do -

1
npm init

And then..

1
npm publish

Lo and behold - your package is ready for reuse.

The Problem

While publishing packages is all dandy, what if you are creating a product that has multiple repositories and developing stuff simultaneously?

The most basic way to solve this will be -

  1. Make changes. Publish
  2. Retrieve package from the consuming application. Rejoice

This may be fine if you are looking at version controlling changes ** after ** development. But the crazy iterations that make up dev/testing may make this arrangement counter productive.

The Solution

While publishing to some sort of repository or initiating a build process from GitHub should be the considered options for teams, crazy individuals may have an easier way out.

Let’s say you are developing aweval and awesub packages. awesub has a dependency on aweval.

Navigate to the project folder of aweval. Do -

1
npm link

This will create a locally available package called aweval.

Now, go to the project folder for awesub. Do -

1
npm link aweval

This will link the awesub project to the locally available aweval project.

Any changes in aweval do not need to be published anymore. You can just start awesub and see the latest features available - as quick as that.

I want more features

See -

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things