npm-config

描述

npm從以下來源獲取配置值,按優(yōu)先級排序:

命令行標(biāo)記

在命令行上放置--foo bar設(shè)置foo配置參數(shù)為bar。 一個 -- 參數(shù)(argument)告訴cli解析器停止讀取flags.一個 在命令行結(jié)尾的--flag參數(shù)(parameter)的值將會是true.

環(huán)境變量

任何以npm_config_開始的環(huán)境變量都會作為配置參數(shù)解讀。在環(huán)境里設(shè)置npm_config_foo=bar將會設(shè)置foo配置參數(shù)為bar。任何沒有值的環(huán)境配置將會默認(rèn)為true。配置值是不區(qū)分大小寫的,所以NPM_CONFIG_FOO=bar的結(jié)果一樣。

npmrc Files

相關(guān)的四個文件是:

  • 每個項(xiàng)目配置文件(/path/to/my/project/.npmrc)
  • 每個用戶配置文件(~/.npmrc)
  • 全局配置文件($PREFIX/etc/npmrc)
  • npm構(gòu)建配置文件(/path/to/npm/npmrc)

查看npmrc了解更多細(xì)節(jié)

默認(rèn)配置

運(yùn)行npm config ls -l查看npm內(nèi)部的配置參數(shù),和沒有特別指定的默認(rèn)值。

縮寫和其他CLI細(xì)節(jié)

以下縮寫會在命令行解析:

  • -v : --version
  • -h, -?, --help, -H: --usage
  • -s, --silent: --loglevel silent
  • -q, --quiet: --loglevel warn
  • -d: --loglevel info
  • -dd,--verbose: --loglevel verbose
  • -ddd, --loglevel silly
  • -g: --global
  • -C: --prefix
  • -l: --long
  • -m: --message
  • -p, --porcelain: --parseable
  • -reg: --registry
  • -f : --force
  • -desc: --description
  • -S: -save
  • -D: --save-dev
  • -O: --save-optional
  • -B: --save-bundle
  • -E: --save-exact
  • -y: --yes
  • -n: --yes false
  • ll and la命名:ls --long

如果指定的配置參數(shù)解析明確已知的配置參數(shù)。比如:

npm ls --par
#same as
npm ls --parseable

如果多個單個字符縮寫串在一起,并且組合沒有去其他配置參數(shù)產(chǎn)生歧義,那么就會擴(kuò)展成多個不同的組成。比如:

npm ls -gpld
# same as
npm ls --global --parseable --long --loglevel info

每個包的配置設(shè)置

當(dāng)運(yùn)行腳本時(看npm-scripts),如果有一個<name>[<@version>]:<key>的配置參數(shù),package.json “config”keys將在環(huán)境變量里被重寫.比如:

{"name":"foo"
,"config":{"port":"8080"}
,"scripts":{"start":"node server.js"}}

并且server.js是這樣的:

http.createServer(...).listen(process.env.npm_package_config_port)

然后用戶可能這樣修改:

npm config set foo:port 80
Config Settings
access
  • Default:restricted
  • Type:Access

當(dāng)發(fā)布scoped packages是,默認(rèn)的訪問等級是restricted.如果你想要scoped package是公共可見的(和可安裝的)。設(shè)置 --access=public. access唯一合法的值是publicrestricted.Unscoped packages的accesslevel總是public.

always-auth
  • Default: false
  • Type:Boolean
    npm在訪問registry的時候強(qiáng)制需要驗(yàn)證,即使是GET請求
also
  • Default: null
  • Type: String
    當(dāng)“dev"或者"development"并且本地運(yùn)行npm shrinkwrap,npm outdated或者npm update,別名是 -dev
bin-links
  • Default: true
  • Type: Boolean
    為可執(zhí)行包告訴npm創(chuàng)建symlinks(在windows是.cmd)

設(shè)置false告訴不要這樣。這是用來解決一些不支持symlink的文件,即使表面是Unix systems.

browser
  • Default: OS X:"open", Windows: "start", Others:"xdg-open"
  • Type: String
    通過npm docs命令調(diào)用瀏覽器打開網(wǎng)站
ca
  • Default: The npm CA 認(rèn)證
  • Type: String, Array或者null
    信任的證書頒發(fā)機(jī)構(gòu)簽名證書的SSL連接到注冊表中.在PEM格式的換行應(yīng)該通過"\n"代替。比如:
ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

設(shè)置null讓只有known登記員,或者指定CA認(rèn)證相信只有特定的登陸認(rèn)證。
多個CAs可以通過數(shù)組形式指定:

ca[]="..."
ca[]="..."

同看strict-ssl配置。

cafile
  • Default: null
  • Type: path
    路徑文件包含一個或多個簽名證書的證書頒發(fā)機(jī)構(gòu)。類似于ca設(shè)置,但允許多個ca的,以及ca信息存儲在磁盤上的文件中。
cache
  • Default: Windows: %AppData%\npm-cache
    , Posix: ~/.npm
  • Type: path
cache-lock-stale
  • Default:60000(1分鐘)
  • Type:Number

the number of ms before cache folder lockfiles are considered stale.

cache-lock-retries
  • Default:10
  • Type:Number

Number of times to retry to acquire a lock on cache folder lockfiles.

cache-lock-wait
  • Default:10000(10秒)
  • Type: Number

Number of ms to wait for cache lock files to expire.

cache-max
  • Default: Infinity
  • Type: Number

The maximum time (in seconds) to keep items in the registry cache before re-checking against the registry.

Note that no purging is done unless the npm cache clean
command is explicitly used, and that only GET requests use the cache.

cache-min
  • Default: 10
  • Type: Number

The minimum time (in seconds) to keep items in the registry cache before re-checking against the registry.

Note that no purging is done unless the npm cache clean
command is explicitly used, and that only GET requests use the cache.

cert
  • Default: null
  • Type: String

當(dāng)訪問registry時傳遞的客戶端認(rèn)證

color
  • Default: true
  • Type: Boolean 或者"always"

如果false,就不會顯示顏色。如果"always",就總是顯示顏色。如果true,只有為ttf file描述才打印顏色代碼

depth
  • Default: Infinity
  • Type: Number

通過npm ls, npm cache lsnpm outdated遞歸目錄時的深度

對于npm outdated,Infinity的設(shè)置將會是0,因?yàn)榻o出更多的信息。想要展示所有包和依賴的outdated狀態(tài),使用一個大數(shù)字,比如:npm outdated --depth 9999.

description
  • Default: true
  • Type: Boolean
    在npm search里展示描述
dev
  • Default: false
  • Type: Boolean

隨包安裝dev-dependencies

注意如果設(shè)置了npat ,dev-dependencies也會被安裝

dry-run
  • Default:false
  • Type:Boolean

表明你不需要讓npm做出任何更新并且只報(bào)告完成了什么。這可以通過修改本地安裝的任何命令,比如:install,update,dedupe,uninstall。這不是當(dāng)前通過網(wǎng)絡(luò)相關(guān)命令honored,比如:dist-tags,owner,publish等等。

editor
  • Default: 設(shè)置編輯器,或者"vi"在Posix上,或者"notepad"在windows上。
  • Type: 編輯器路徑(path)

命令運(yùn)行行npm edit或者npm config edit

engine-strict
  • Default: false
  • Type: Boolean

如果設(shè)置為true,npm將會直接拒絕安裝(即使考慮安裝)任何與當(dāng)前Node.js版本不兼容的包

force
  • Default: false
  • Type: Boolean

讓變量命令更強(qiáng)硬

  • 生命周期腳本失敗不阻塞進(jìn)程
  • 發(fā)布時銷毀之前的發(fā)布的版本
  • 從registry里請求時跳過緩存
  • 對非npm文件不檢查
fetch-retries
  • Default:2
  • Type: Number

當(dāng)從registry獲取包時,對retry module使用"retries"配置

fetch-retry-factor
  • Default: 10
  • Type: Number

獲取包時,對retry module使用"factor"配置

fetch-retry-mintimeout
  • Default: 10000(10秒)
  • Type: Number

獲取包時,設(shè)置retry module的"minTimeout"

fetch-retry-maxtimeout
  • Default: 10000(10秒)
  • Type: Number

獲取包時,設(shè)置retry module的"maxTimeout"

git
  • Default: "git"
  • Type: String

使用git命令。如果電腦上安裝了git,但是不在path里,需要將這個設(shè)置為git的全路徑

git-tag-version
  • Default: true
  • Type: Boolean

使用npm version命令時標(biāo)記提交

global
  • Default: false
  • Type: Boolean

使用全局模式,包會安裝到prefix文件夾而不是當(dāng)前工作目錄。 查看npm-folders獲取更多的不同行為

  • packages安裝進(jìn){prefix}/lib/node_modules}文件夾,而不是當(dāng)前工作目錄
  • bin files指向{prefix}/bin
  • man pages 指向** {prefix}/share/man**
globalconfig
  • Default: {prefix}/etc/npmrc
  • Type: path

配置全局配置選項(xiàng)的文件

global-style
  • Default: false
  • Type: Boolean

讓npm安裝到本地的node_modules文件夾和全局的node_moudules文件夾是相同的布局。只有直接依賴的會顯示到node_modules并且依賴所依賴的會平級的在他們的node_modules文件夾。這顯然會消除一些重復(fù)。如果帶有legacy-bundling,legacy-bundling會更好

group
  • Default: 當(dāng)前進(jìn)程的GID
  • Type: String or Number

the group to use when running package scripts in global mode as the root user.

heading
  • Default: "npm"
  • Type: String

所有調(diào)試日志輸出開頭的字符

https-proxy
  • Default: null
  • Type: url

用于代理https請求的。

if-present
  • Default: false
  • Type: Boolean

If true, npm will not exit with an error code when run-script
is invoked for a script that isn't defined in the scripts
section of package.json
. This option can be used when it's desirable to optionally run a script when it's present and fail if the script fails. This is useful, for example, when running scripts that may only apply for some builds in an otherwise generic CI setup.

ignore-scripts
  • Default: false
  • Type: Boolean

是true的話,npm不運(yùn)行在pacakge.json文件里指定的腳本

init-module
  • Default: ~/.npm-init.js
  • Type: path

會被npm init命令加載的模塊。從init-pacakge-json文檔獲取更多信息,或者npm-init

init-author-name
  • Default: ""
  • Type: String
    執(zhí)行npm init是默認(rèn)給包設(shè)置的作者名
init-author-email
  • Default: ""
  • Type: String
    執(zhí)行npm init是默認(rèn)給包設(shè)置的作者的郵件
init-author-url
  • Default: ""
  • Type: String
    執(zhí)行npm init是默認(rèn)給包設(shè)置的作者的主頁
init-license
  • Default: "ISC"
  • Type: String
    執(zhí)行npm init是默認(rèn)給包設(shè)置的默認(rèn)證書
init-version
  • Default: ""
  • Type: String
    如果pacakge.json里沒有設(shè)置,執(zhí)行npm init是默認(rèn)給包設(shè)置的版本號
json
  • Default: false
  • Type: Boolean

是否輸出JSON data,而不是普通輸出

這個特性目前只是實(shí)驗(yàn)階段,許多命令的輸出結(jié)構(gòu)還沒有實(shí)現(xiàn)JSON,或者可能發(fā)生變化。只有npm ls --json命令才是有效的。

key
  • Default: null
  • Type: String
    訪問registry傳輸?shù)目蛻舳薻ey
legacy-bundling
  • Default: false
  • Type: Boolean

Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping. If used with global-style
this option will be preferred.

link
  • Default: false
  • Type: Boolean

if true, 局部安裝會鏈接到合適的全局安裝了的包。

注意這意味著局部安裝會在同一時間導(dǎo)致things被安裝進(jìn)全局空間。只有兩種條件之一發(fā)生時link才會完成:

  • 包還沒有被安裝到全局環(huán)境,或者
  • 全局安裝的版本表明已經(jīng)被安裝到了局部
local-address
  • Default: undefined
  • Type: IP Address

在連接到npm registry是的本地接口的ip地址。Node小于0.12時必須是IPv4.

loglevel
  • Default: "warn"
  • Type: String
  • Values: "silent", "error", "warn", "http", "info", "verbose", "silly"

日志輸出的等級。失敗的時候,所有的日志會寫到當(dāng)前工作目錄的npm-debug.log

任何高于設(shè)置等級的日志都會被輸出,默認(rèn)是"warn",就會輸出"warn","error"

logstream
  • Default: process.stderr
  • Type: Stream

在運(yùn)行時傳給npmlog的stream

如果不能從命令行里設(shè)置,但是正以編程方式使用npm,你可能想將日志存在其他地方而不是stderr。

如果設(shè)置了color為true,如果stream是TTY,那么會接收到colored輸出。

long
  • Default: false
  • Type: Boolean

npm lsnpm search展示更多的信息

message
  • Default: "%s"
  • Type: String

使用npm version創(chuàng)建版本提交時提交信息。

message里的任何"%s"都會被替換成版本號

node-version
  • Default: process.version
  • Type: semver or false

當(dāng)檢查package's enginesmap時的node版本號

npat
  • Default: false
  • Type: Boolean

在安裝時運(yùn)行測試

onload-script
  • Default: false
  • Type: path

在npm加載時,node模塊去require()。在編程時的用法。

only
  • Default: null
  • Type: String

當(dāng)是dev或者development時,不帶任何參數(shù)運(yùn)行局部npm install,只會有devDependencies(和他們的依賴)會被安裝

當(dāng)是dev或者development時,運(yùn)行npm ls, npm outdated或者npm update,是 --dev的別名

當(dāng)是prod或者production是,無參運(yùn)行npm install,只有non-devDependencies(和他們的依賴)會被安裝。運(yùn)行npm ls, npm outdated或者npm update,是 --production的別名

optional
  • Default: true
  • Type: Boolean

試圖安裝在optionalDependencies對象里的包。注意如果包安裝失敗了,整個安裝過程不會終止。

parseable
  • Default: false
  • Type: Boolean

從命令行里的標(biāo)準(zhǔn)輸出解析輸出結(jié)構(gòu)

prefix

安裝全局項(xiàng)的位置,如果在命令行上設(shè)置,會強(qiáng)制非全局命令在指定文件夾里運(yùn)行

production
  • Default: false
  • Type: Boolean

是true就是production模式:

  1. 無參運(yùn)行npm install時不會將devDependencies安裝在最高的等級
  2. 為生命周期腳本設(shè)置NODE_ENV="production"
progress
  • Default: true
  • Type: Boolean

是true時,如果在處理中,npm會顯示一個進(jìn)度條。stderr是一個TTY。

false就沒有進(jìn)度條

properietary-attribs
  • Default: true
  • Type: Boolean

在npm創(chuàng)建壓縮包時是否包含私人擴(kuò)展屬性

Unless you are expecting to unpack package tarballs with something other than npm -- particularly a very outdated tar implementation -- leave this as true.

proxy
  • Default: null
  • Type: url

外部請求的代理。如果設(shè)置了HTTP_PROXY或者http_proxy環(huán)境變量,proxy設(shè)置將會由底層請求庫

rebuild-bundle
  • Default: true
  • Type: Boolean

在安裝后重新構(gòu)建包依賴

registry

基于npm 包registry的鏈接

rollback
  • Default: true
  • Type: Boolean

刪除失敗的安裝

save
  • Default: false
  • Type: Boolean

安裝包時,作為dependencies保存到package.json

當(dāng)使用npm rm命令,會從dependencies對象里刪除

只有當(dāng)已經(jīng)有package.json文件時才有效。

save-bundle
  • Default: false
  • Type: Boolean

通過使用--save, --save-dev或者--save-optional,包是否會在安裝時保存,然后也放到bundleDependencieslist里。

使用npm rm命令時,會從bundledDependencieslist里移除

save-dev
  • Default: false
  • Type: Boolean

安裝包時,作為devDenpendencies保存到package.json

使用npm rm命令時,會從devDenpendencieslist里移除

僅當(dāng)存在package.json文件時才有效。

save-exact
  • Default: false
  • Type: Boolean
    使用--save,--save-dev或者-save-optional是保存Dependencies到pacakge.json會配置要求版本而不是npm的默認(rèn)semver范圍
save-optional
  • Default: false
  • Type: Boolean

保存安裝包到package.json里的optionalDependencies里。

使用npm rm命令時,會從devDependencies對象里移除

僅當(dāng)存在package.json文件時才有效。

save-prefix
  • Default:'^'
  • Type: String

通過--save或者--save-dev獲取prefixed配置包的什么版本到package.json

比如:如果包有一個版本1.2.3,但是默認(rèn)設(shè)置的版本是可以允許小的升級包的^1.2.3。但是在npm config set save--prefix='~'后,應(yīng)該設(shè)置為~1.2.3

scope
  • Default: ""
  • Type: String

Associate an operation with a scope for a scoped registry. Useful when logging in to a private registry for the first time: npm login --scope=@organization --registry=registry.organization.com, which will cause @organization to be mapped to the registry for future installation of packages specified according to the pattern @organization/package

searchopts
  • Default: ""
  • Type: String
    搜索時空格分隔的選項(xiàng)
searchexclude
  • Default:""
  • Type: String
    空格分隔的選項(xiàng)限制搜索的結(jié)果。
searchsort
  • Defautl: "name"
  • Type: String
  • Values:"name","-name","date","-date","description","-description","keywords","-keywords"

顯示的字段排序搜索結(jié)果。前綴-表明逆向排序。

shell
  • Default: SHEELL環(huán)境變量,Posix上是base,windows上是cmd
  • Type: path

運(yùn)行npm explore命令的shell

shrinkwrap
  • Default: true
  • Type: Boolean

如果是false,安裝時會忽略掉npm-shrinkwrap.json

sign-git-tag
  • Default: false
  • Type: Boolean

為true時,npm version命令會使用-s標(biāo)記版本添加到signature.

注意git需要你設(shè)置GPG keys,在git配置這個工作屬性

strict-ssl
  • Default: true
  • Type: Boolean

通過https請求registry是否進(jìn)行SSL可以驗(yàn)證,同ca配置

tag
  • Default:latest
  • Type: String

如果在安裝包時不告訴指定的版本,就會安裝指定的tag

同樣tag會添加到pacakge@version,通過npm tag命令指定,如果沒有顯示的tag給

tag-version-prefix
  • Default: "v"
  • Type: String

If set, alters the prefix used when tagging a new version when performing a version increment using npm-version. To remove the prefix altogether, set it to the empty string: "".
Because other tools may rely on the convention that npm version tags look likev1.0.0
, only use this property if it is absolutely necessary. In particular, use care when overriding this setting for public packages.

tmp
  • Default: TMPDIR environment variable, or "/tmp"
  • Type: path

Where to store temporary files and folders. All temp files are deleted on success, but left behind on failure for forensic purposes.

unicode
  • Default: false on windows, true on mac/unix systems with a unicode locale
  • Type: Boolean

When set to true, npm uses unicode characters in the tree output. When false, it uses ascii characters to draw trees.

unsafe-perm
  • Default: false if running as root, true otherwise
  • Type: Boolean

Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.

usage
  • Default: false
  • Type: Boolean

Set to show short usage output (like the -H output) instead of complete help when doing npm-help

user
  • Default: "nobody"
  • Type: String or Number

The UID to set to when running package scripts as root.

userconfig
  • Default: ~/.npmrc
  • Type: path

The location of user-level configuration settings.

umask
  • Default: 022
  • Type: Octal numeric string in range 0000..0777 (0..511)

The "umask" value to use when setting the file creation mode on files and folders.

Folders and executables are given a mode which is 0777 masked against this value. Other files are given a mode which is 0666 masked against this value. Thus, the defaults are 0755 and 0644 respectively.

user-agent
  • Default: node/{process.version} {process.platform} {process.arch}
  • Type: String

Sets a User-Agent to the request header

version
  • Default: false
  • Type: boolean

If true, output the npm version and exit successfully.

Only relevant when specified explicitly on the command line.

versions
  • Default: false
  • Type: boolean

If true, output the npm version as well as node's process.versions map, and exit successfully.

Only relevant when specified explicitly on the command line.

viewer
  • Default: "man" on Posix, "browser" on Windows
  • Type: path

The program to use to view help content.

Set to "browser" to view html help content in the default web browser.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,641評論 19 139
  • 中文翻譯 ng help ng build 構(gòu)建您的應(yīng)用程序并將其放入輸出路徑(dist /默認(rèn)情況下)。 別名:...
    4ea0af17fd67閱讀 2,141評論 0 0
  • =========================================================...
    lavor閱讀 3,649評論 0 5
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 9,066評論 0 6
  • 愿你永遠(yuǎn)年輕,永遠(yuǎn)熱淚盈眶 ——《達(dá)摩流浪者》 第一次看《小王子》的是小學(xué)三年級。那...
    王汪汪vicky閱讀 492評論 0 0

友情鏈接更多精彩內(nèi)容