使用场景:

前端项目的编译运行开发中报下载经常出错:
项目场景:通常我们前端项目开发搭建过程中通过npm管理前端js库,新建项目或内网开发过程中经常出现环境搭建的问题,例如常见错误Failed at the chromedriver@2.37.0 install script 'node install.js',node-sass安装失败等,通过verdaccio搭建npm私有仓库,让前端开发环境搭建提速。

  • 外网环境安装Verdaccio
  • Verdaccio运行,添加项目及依赖包
  • 拷贝npm文件到内网电脑

环境检查:

保证内网电脑与外网电脑的 nodejs版本一致,保证前端项目中使用的node-sass版本与nodejs兼容,nodeModule版本是 node-sass的项目模块

NodeJS node-sass version Node Module
Node 14 4.14+ 83
Node 13 4.13+ 79
Node 12 4.12+ 72
Node 11 4.10+ 67
Node 10 4.9+ 64
Node 8 4.5.3+ 57

关于Node版本:

根据我们项目中依赖node-sass的版本,我们选中向下兼容安装nodejs.根据项目的node-sass,

"dependencies": {"abab": "^1.0.4","axios": "0.17.1","babel-plugin-component": "0.10.1","babel-polyfill": "6.26.0","chromedriver": "^89.0.0","element-ui": "2.8.2","emoji-regex": "^7.0.1","gulp": "4.0.2","gulp-concat": "2.6.1","gulp-load-plugins": "2.0.5","gulp-replace": "1.0.0","gulp-shell": "0.8.0","lodash": "4.17.5","node-sass": "^4.13.1","npm": "^6.9.0","sass-loader": "6.0.6","strip-bom": "^3.0.0","svg-sprite-loader": "3.7.3","vue": "2.5.16","vue-cookie": "1.1.4","vue-router": "3.0.1","vuex": "3.0.1"},

我机器上安装的node 是

$ node -v
v13.14.0

配置文件位置:

外网电脑,verdaccio安装,启动:

安装,在Git Bash中运行命令

npm install --global verdaccio

启动,在命令行运行, verdaccio,启动成功可通过 http://127.0.0.1:4873/ ,访问Verdaccio界面, 其中打印信息中有 配置文件位置:C:\Users\lch.config\verdaccio\config.yaml,

lch@desktop-n6td65m MINGW64 ~/Desktop
$ verdacciowarn --- config file  - C:\Users\lch\.config\verdaccio\config.yamlwarn --- Verdaccio startedwarn --- Plugin successfully loaded: verdaccio-htpasswdwarn --- Plugin successfully loaded: verdaccio-auditwarn --- http address - http://0.0.0.0:4873/ - verdaccio/4.12.0

发布项目到verdaccio:

当前npm 服务指向 本地

npm set registry http://localhost:4873

注册用户

npm adduser –registry http://localhost:4873

按照提示录入用户名密码

发布项目到Verdaccio

到开发的项目根目录下即package.json的目录,执行命令:

npm publish

发布好项目了

安装项目的依赖到verdaccio

删除项目的node_modules文件夹,执行命令:

npm install --registry http://localhost:4873

首先会去 本地的 verdaccio下载依赖,如果本地没有会去 uplinks 配置的公有仓库下载,并缓存到 storage 文件夹下。根据配置文件的位置,我们找到storage的文件夹位置:C:\Users\lch.config\verdaccio\storage
这个过程应该是异步过程,等安装完成后,需要等一会verdaccio缓存才会完成。


部署到内网(离线环境):

内网安装好 nodejs(与外网版本保持一致) 和 git bash后,
我们拷贝 npm全局目录与缓存目录及verdaccio的依赖库目录到覆盖内网的对应目录中。

覆盖npm全局目录及缓存目录

npm全局目录及缓存目录默认在:

C:\Users\用户名\AppData\Roaming\npm

用户名为当前登录用户,也可能是在

C:\Users\Administrator\AppData\Roaming\npm

如果你修改了全局目录和缓存目录,使用命令

npm config ls

查看全局目录位置

prefix = "C:\\Users\\lch\\AppData\\Roaming\\npm"

覆盖verdaccio缓存目录

verdaccio的安装文件已经在npm的全局目录中了,我们还要复制一份缓存目录到内网机器用户的.config目录下
外网目录:C:\Users\lch\.config\verdaccio
内网目录:C:\Users\用户名\.config\verdaccio

离线环境运行

同外网,启动verdaccio 启动后访问:

如果内网环境中没有发布项目了,说明配置文件可能不对,将npm全局目录下的
default.yaml文件内容替换成 verdaccio 缓存目录下的 config.yaml 内容

\npm\node_modules\verdaccio\conf\default.yaml
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
## path to a directory with all packages
#storage: ./storage
storage: C:\\Users\\lch\\.config\\verdaccio\\storage
# path to a directory with plugins to include
#plugins: ./plugins
plugins: C:\\Users\\lch\\.config\\verdaccio\\pluginsweb:title: Verdaccio# comment out to disable gravatar support# gravatar: false# by default packages are ordercer ascendant (asc|desc)# sort_packages: asc# convert your UI to the dark side# darkMode: true# translate your registry, api i18n not available yet
# i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
#   web: en-USauth:htpasswd:file: ./htpasswd# Maximum amount of users allowed to register, defaults to "+inf".# You can set this to -1 to disable registration.# max_users: 1000# a list of other known repositories we can talk to
uplinks:npmjs:url: https://registry.npmjs.org/packages:'@*/*':# scoped packagesaccess: $allpublish: $authenticatedunpublish: $authenticatedproxy: npmjs'**':# allow all users (including non-authenticated users) to read and# publish all packages## you can specify usernames/groupnames (depending on your auth plugin)# and three keywords: "$all", "$anonymous", "$authenticated"access: $all# allow all known users to publish/publish packages# (anyone can register by default, remember?)publish: $authenticatedunpublish: $authenticated# if package is not available locally, proxy requests to 'npmjs' registryproxy: npmjs# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:keepAliveTimeout: 60middlewares:audit:enabled: true
# 监听的端口 ,重点, 不配置这个,只能本机能访问
listen: 0.0.0.0:4873
# 允许离线发布
publish:allow_offline: true
# log settings
logs:- { type: stdout, format: pretty, level: http }#- {type: file, path: verdaccio.log, level: info}
#experiments:
#  # support for npm token command
#  token: false
#  # support for the new v1 search endpoint, functional by incomplete read more on ticket 1732
#  search: false
#  # disable writing body size to logs, read more on ticket 1912
#  bytesin_off: false# This affect the web and api (not developed yet)
#i18n:
#web: en-US

verdaccio内网离线搭建npm私有仓库相关推荐

  1. 使用verdaccio 搭建npm私有仓库

    使用verdaccio 搭建npm私有仓库 1. 为什么要搭建私有的npm仓库?     随着公司的业务越来越复杂,项目迭代速度也越来越快,那么项目间的常用的业务代码共享变得非常之有必要.但是对于公司 ...

  2. Linux搭建GitLab私有仓库,并内网穿透实现公网访问

    文章目录 前言 1. 下载Gitlab 2. 安装Gitlab 3. 启动Gitlab 4. 安装cpolar 5. 创建隧道配置访问地址 6. 固定GitLab访问地址 6.1 保留二级子域名 6. ...

  3. 前端人员如何在linux服务器上搭建npm私有库

    为什么要搭建npm私有库? 为了方便下载时,公共包走npmjs,私有包走内部服务器. npm包下载的速度较慢,搭建npm私有库之后,会先操作私有库中是否有缓存,有缓存直接走缓存,而不用重新再去请求一遍 ...

  4. 搭建Maven私有仓库

    内部的项目并且需要多团队协作模块化开发的时候,自然会想到搭建自己的maven私有仓库,本文主要介绍如何搭建maven私服和如何在项目中添加依赖. Maven 的远程仓库分为中央仓库和私服仓库.中央仓库 ...

  5. Docker容器之搭建本地私有仓库

    Docker容器之搭建本地私有仓库 前言 一.首先下载registry镜像 二.在daemon.json文件中添加私有镜像仓库的地址并重启 三.创建registry容器并开放端口 四.给镜像打标签后上 ...

  6. 1+X 云计算运维与开发(中级)案例实战——搭建harbor私有仓库并实现主从同步

    1+X 云计算运维与开发(中级)案例实战--搭建harbor私有仓库并实现主从同步 前言 思路 实操 1.(个人习惯)修改主机名,添加主机映射 2. 配置镜像加速器 3. 生成CA证书,并分发证书 4 ...

  7. linux 内网环境搭建 maven 私库

    linux 内网环境搭建 maven 私库 参考资料: https://www.codenong.com/cs106446840/ https://blog.csdn.net/lch_wyl/arti ...

  8. 基于frp的内网穿透搭建指南

    目录 一.前言介绍 二.正文 1.准备事项 2.服务端配置 3.客户端配置 a.Windows端配置 b.Linux端配置 c.p2p配置 三.总结 一.前言介绍 由于全球ipv4地址资源的紧张,大多 ...

  9. CentOS7.3服务器内网离线部署docker和容器

    目录 CentOS7.3服务器内网离线部署docker和容器 一.离线安装docker 1.获取yum仓库中的docker及其依赖包 2.安装docker 3.安装docker-compose 4.启 ...

最新文章

  1. tensorflow eager调试模式关键导入如下两行便于debug
  2. 正則表達式基本元字符集及其含义(上)
  3. 【Linux】32. shell脚本 定时删除 过时 的某类文件
  4. 各种拿webshell
  5. Vue 响应式原理(双向数据绑定) 怎样实现 响应式原理?
  6. 天河二号超级计算机拿来玩游戏,“天河二号超级计算机”是我国独立自主研制的超级计算机系统,...
  7. pkill mysql_每天一个linux命令:kill命令
  8. 读书笔记:《一生的计划》
  9. 安卓自定义相机录像功能全解(不调用系统相机)
  10. 【每日算法Day 69】面试经典题:分发糖果问题
  11. 阿里云Centos6.6安装配置docker
  12. P4556 [Vani有约会] 树上差分 + 线段树合并
  13. html5制作涂鸦板,HTML5实现涂鸦板
  14. 2017中国十大富豪排行榜
  15. jQuery元素操作-遍历元素
  16. 用API函数使程序标题栏闪烁
  17. 折腾一下,Linux Mint 19 下工作
  18. HCIA 的认证证书含金量?
  19. 用户手册——机房收费系统
  20. “杰林码”技术及应用

热门文章

  1. matlab数值解方程,[原创]MATLAB的Mupad应用之以数值方法解方程
  2. 蓝桥杯-迷宫(17年)-python
  3. 中国石油大学《管理学》在线考试
  4. cmake -- No rule to make target xxx.so
  5. 【Python】信用评级项目——个人评分A卡制作
  6. 以牌照搜题为例,简单分析文字切割与识别部分
  7. MySQL 子查询,多表联合查询,视图,存储过程详解
  8. linux系统怎么设置硬链接,二、Linux系统硬链接和软链接详细介绍与实践
  9. 2020年6月6日更新 上海居住证办理流程
  10. [运维] - 服务器的初始化流程