企业内部前端代码复用通常使用自建 NPM Registry 实现,然而这种使用方式需要相对完善的基础设施建设。 这里推荐一种短平快的使用方式,即使用 GitLab 进行私有前端公共库管理,并且简单记录一下如何将其安装到实际项目里去。 创建项目我们创建一个 hello-world 公共库项目,然后在其中使用 npm init 初始化一个 package.json 文件,内容参考如下。 { "name": "hello-world", "version": "1.0.0", "private": true, "description": "Hello World", "main": "index.js", "repository": { "type": "git", "url": "git@git.example.com:bayunjiang/hello-world.git" }, "author": "bayunjiang", "license": "ISC"