How to install NPM package under alias or different name

房东的猫 提交于 2020-03-03 03:53:09

问题


How can I npm install a package into a different directory?


回答1:


Say you want to install Case package, you can have a specific version under an alias:

npm i case-1.5.3@npm:case@1.5.3

or just give it a different name

npm i kool@npm:case

If you want to edit package.json directly:

"dependencies": {
  "case-1.5.3": "npm:case@^1.5.3",
  "kool": "npm:case@^1.6.1"
}

require():

let Case = require( 'case-1.5.3' );
let Kool = require( 'kool' );

Yarn used to have this functionality for a long time, and npm finally got it since v6.9.0, Mar 2019.

If you want to update your npm:

sudo npm i -g npm@latest


来源:https://stackoverflow.com/questions/56134857/how-to-install-npm-package-under-alias-or-different-name

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