npm
npm docs <pkg> # open the docs of pkg
npm repo <pkg> # open the repository of pkg
npm run-script <command> [--if-present] [--silent] [-- <args>]
传参
--a=1
"scripts": {
"test": "node app.js", // 1
}
npm run test --a=1
> trader@1.0.0 test
> node app.js "1"
[
'xxx',
'xxx/app.js',
'1' // process.argv[2]
]
undefined
-- --a=1
npm run test -- --a=1
> trader@1.0.0 test
> node app.js "--a=1"
[
'xxx',
'xxx/app.js',
'--a=1'
]
npm 配置 github registry
编辑 ~/.npmrc
//npm.pkg.github.com/:_authToken=xxxx # xxx 为github personal access token
Refer
npm 安装 github private 包
details
# Use default ssh account
npm i git@github.com:xxx/xxx.git
# # Or use another ssh account
# npm i git+ssh://xxxx:xx/xx.git
.npmrc
details
1. 全局配置 .npmrc
文件
如果你想为整个系统的 npm 配置创建一个全局 .npmrc
文件,可以通过以下命令进行操作:
npm config set <key> <value>
例如,你可以设置全局 registry
(npm 的镜像源):
npm config set registry https://registry.npmjs.org/
这将会在你的用户目录下(如 ~/.npmrc
)创建一个 .npmrc
文件。
2. 项目级 .npmrc
文件
如果你想为特定的项目创建 .npmrc
文件,直接在项目根目录下手动创建该文件,或者可以使用 npm config
命令为该项目添加特定的配置。
在项目根目录下运行以下命令:
npm config set <key> <value> --location=project
例如,为项目设置镜像源:
npm config set registry https://registry.npmjs.org/ --location=project
这将在你的项目根目录下生成或修改 .npmrc
文件。
3. 手动创建 .npmrc
文件
你也可以直接手动在项目目录下创建 .npmrc
文件,并根据需要添加配置,例如:
registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=<your-auth-token>