Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude dev dependencies when publishing npm package

So I'm in the process of publishing a package to npm. It is basically just a simple module that lets users make Ajax calls and can be configured in a few ways.

I have read that it is a good idea to test the install locally and tried that. I have packed the package via the "npm pack" command, change into another directory and then tried installing the packge via "npm install path-to-file-that-was-just-created.tgz". So far everything works, I have a node_modules folder, that contains my bundled code.

However, is also has installed all the dependencies that I have listed as devDependencies in the package.json of my actual module, even though the only the bundled file is needed and no other depenedencies are defined. I have tried updating the npm-shrinkwrap.json, and checked that every dependency has the dev property marked as true.

The goal is actually for the user to install this module and then have no dependencies installed, because they do not need babel or mocha, to run the module. How can I exclude these from the packge? Thanks!

like image 995
Marcus Avatar asked Dec 19 '17 17:12

Marcus


People also ask

How do I get rid of dev dependencies?

To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located.

Why is npm installing dev dependencies?

Development dependencies are intended as development-only packages, that are unneeded in production. For example testing packages, webpack or Babel. When you go in production, if you type npm install and the folder contains a package. json file, they are installed, as npm assumes this is a development deploy.

Does npm install dev dependencies by default?

By default, npm install will install all modules listed as dependencies in package. json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .

How does npm detect dev dependencies?

When you (or another user) run npm install , npm will download dependencies and devDependencies that are listed in package. json that meet the semantic version requirements listed for each. To see which versions of a package will be installed, use the semver calculator.


1 Answers

https://docs.npmjs.com/cli/install

use the --production flag to avoid installing dev dependencies

For published modules, you don't need to do anything, when a user installs your library, only the non-dev dependencies will be installed

like image 113
Pubudu Dodangoda Avatar answered Sep 22 '22 10:09

Pubudu Dodangoda