Install npm package without dependencies

喜欢而已 提交于 2019-11-30 19:27:29

问题


I am looking for best solution how to install npm package without it's dependencies described in it's package.json file.

The goal is to change dependencies versions before install package. I can do it manually for one package by downloading source, but if you have many nested dependencies it becomes a problem.


回答1:


Here's a shell script that seems to get you the extracted files you need.

#!/bin/bash
package="$1"
version=$(npm show ${package} version)
archive="${package}-${version}.tgz"
curl --silent --remote-name \
  "https://registry.npmjs.org/${package}/-/${archive}"
mkdir "${package}"
tar xzf "${archive}" --strip-components 1 -C "${package}"
rm "${archive}"

Save it as npm_download.sh and run it with the name of the package you want:

./npm_download.sh pathval




回答2:


Please check simialr quesition on stackexchange: https://unix.stackexchange.com/questions/168034/is-there-an-option-to-install-an-npm-package-without-dependencies

My solution was to rename package.json to package.bak before the install, then reverting rename afterwards:

RENAME package.json package.bak
npm install <package_name> --no-save
RENAME package.bak package.json


来源:https://stackoverflow.com/questions/28382773/install-npm-package-without-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!