How I Avoid Installing npm Packages Globally

First, I take the installations instructions, but instead of installing globally, I install as a dev dependency inside my project (webpack used for this example):

[fz_snippet snippet_number=1]

Second, I check the node_modules bin directory to confirm that I have the webpack binary

[fz_snippet snippet_number=2]

That directory contains symlinks to all the binaries installed with npm for a specific project

The contents of a node_modules/.bin directory

Third, I create an npm script for easily running the binary found in step 2

in package.json, add the following to your package.json file in your scripts:

[fz_snippet snippet_number=3]

Here’s how it looks in a project I setup:

[fz_snippet snippet_number=4]

Now you can run the following command from any directory in your project and it will run webpack for you

[fz_snippet snippet_number=5]

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *