注册npm账号

注册地址

私有NPM包

采用git的方式来创建npm私有组件

创建git仓库

  • Git仓库可选择github、gitlab、coding等。

image.png

  • 本地创建项目文件夹。
  • 将私有库克隆到创建的本地项目文件夹。image.png

    1. git clone https://e.coding.net/lululul/nepnpm/pnpm.git
  • cd到项目文件夹并执行命令,生成package.json文件。

    1. npm init --scope=pnpm(文件名)

    image.png

  • 上传到远程仓库。

    1. git add .
    2. git commit -m "init"
    3. git push
    4. git tag 0.0.1
    5. git push --tags

创建本地npm工程

执行创建命令

  1. ng new myPrivate --skip-npm

-bash: ng: command not found

image.png

处理方案

ng 命令是Angular命令。执行命令安装。

  1. sudo npm install -g @angular/cli

image.png

生成本地npm项目

  1. ng new myPrivate

image.pngimage.png

编辑package.json文件添加私有组件链接

image.png

执行命令生成私有npm组件链接

  1. npm install

image.png

引用npm私有组件

命令引入私有npm组件

  1. npm i git+https://e.coding.net/lululul/nepnpm/pnpm.git#0.0.1

image.png
image.png

在uni-app项目中使用命令时需要手动创建node_modules文件夹。 尽量使用tag方式进行引入。