资源node
原来用sinopia搭建的私服,但sinopia两年年中止维护了,如今改成verdaccio。使用verdaccio也超级简单,只需几分钟就能够搭建一个私服,适合公司内部不对外的包的安装git
$ yarn global add verdaccio yarn global v1.12.3 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "verdaccio@3.10.1" with binaries: - verdaccio Done in 52.10s.
安装到了 C:\Users\Administrator\AppData\Local\Yarn\bin
[个人是win10]github
或npm install --global verdaccio
安装shell
随便建一个空目录测试,我当前工做目录是F:\youshengyouse\del3
npm
$ verdaccio warn --- config file - C:\Users\Administrator\.config\verdaccio\config.yaml warn --- Plugin successfully loaded: htpasswd warn --- Plugin successfully loaded: audit warn --- http address - http://localhost:4873/ - verdaccio/3.10.1
在浏览器输入http://localhost:4873/
,结果以下json
另开一个命令行窗口,原来的verdaccio仍在运行浏览器
$ npm adduser --registry http://localhost:4873 Username: abcd Password: qwer Email: (this IS public) a@163.com Logged in as abcd on http://localhost:4873/.
当前工做目录:要发布哪一个包,当前目录切换到包根目录下缓存
$ npm publish --registry http://localhost:4873 > gatsby2-cli@1.0.0 prepare . > cross-env NODE_ENV=production npm run build > gatsby2-cli@1.0.0 build F:\youshengyouse\frontend\packages\gatsby\packages\gatsby2-cli > babel src --out-dir lib --ignore **/__tests__ Successfully compiled 6 files with Babel. npm notice npm notice package: gatsby2-cli@1.0.0 npm notice === Tarball Contents === npm notice 1.8kB package.json npm notice 7.4kB CHANGELOG.md npm notice 3.3kB README.md npm notice 9.4kB lib/create-cli.js npm notice 2.7kB lib/index.js npm notice 4.7kB lib/init-starter.js npm notice 2.0kB lib/reporter/errors.js npm notice 3.1kB lib/reporter/index.js npm notice 4.0kB lib/reporter/prepare-stack-trace.js npm notice === Tarball Details === npm notice name: gatsby2-cli npm notice version: 1.0.0 npm notice package size: 11.0 kB npm notice unpacked size: 38.3 kB npm notice shasum: 64c9c47b81610731e559bc33f86aa02f87155656 npm notice integrity: sha512-vhroNpnWCwivE[...]8hAg+z6SPOeyw== npm notice total files: 9 npm notice + gatsby2-cli@1.0.0
如今刷新http://localhost:4873/#/
就能够看到刚才发布的包
问题:本地安装的包放在哪里了呢?babel
npm set registry http://localhost:4873/
查看仓库frontend
npm config get registry
$ npm init # 若是没有package.json文件得先建 $ yarn add gatsby2-cli
发现gatsby2-cli是在本地的,其他的依赖仍是从npmjs.com仓库中安装的
问题1:太费空间,想办法解决,全局缓存在C盘
解决办法:从新配置npm
npm的配置文件是 C:\Users\Administrator\.npmrc
看下配置
$ npm config list ; cli configs metrics-registry = "https://registry.npmjs.org/" scope = "" user-agent = "npm/6.4.1 node/v10.15.0 win32 x64" ; builtin config undefined prefix = "C:\\Users\\Administrator\\AppData\\Roaming\\npm" ; node bin location = E:\Program Files\nodejs\node.exe ; cwd = F:\youshengyouse\del3 ; HOME = C:\Users\Administrator ; "npm config ls -l" to show all defaults.
修改prefix为 E:\Program Files\nodejs
# 修改缓存地址 $ npm config set cache "E:\Program Files\nodejs\node_cache2019" # 修改全局放置位置 $ npm config set prefix "E:\Program Files\nodejs"
如今配置以下
$ npm config list ; cli configs metrics-registry = "http://localhost:4873/" scope = "" user-agent = "npm/6.4.1 node/v10.15.0 win32 x64" ; userconfig C:\Users\Administrator\.npmrc ca = null cache = "E:\\Program Files\\nodejs\\node_cache2019" prefix = "E:\\Program Files\\nodejs" registry = "http://localhost:4873/" ; builtin config undefined ; node bin location = E:\Program Files\nodejs\node.exe ; cwd = F:\youshengyouse\frontend\packages\gatsby\www ; HOME = C:\Users\Administrator ; "npm config ls -l" to show all defaults.
全局安装
$ npm i -g gatsby-cli E:\Program Files\nodejs\gatsby -> E:\Program Files\nodejs\node_modules\gatsby-cli\lib\index.js + gatsby-cli@3.0.0 added 211 packages from 119 contributors in 121.998s
会安装在E:\Program Files\nodejs\node_modules\gatsby-cli
,同时E:\Program Files\nodejs\gatsby和gatsby.cmd
两个shell命令也同时安装
配置环境变量 E:\Program Files\nodejs\node_modules
,这样在任何地方能够全局执行gatsby
了
npm config set registry https://registry.npmjs.org