npm 发包小记

npm 发布包过程,和一些可以用到的工具。

发包过程

首先要有个账号,到 npm 官网上注册即可。

添加用户

~ npm adduser
Username:
Password:
Email:

登录

~ npm login
Username:
Password:
Emial:

发布

~ npm publish

取消发布

~ npm unpublish

私服

~ npm adduser --registry http[s]://demo.com
~ npm login --registry http[s]://demo.com
~ npm publish --registry http[s]://demo.com
~ npm unpublish --registry http[s]://demo.com

package.json 文件

{
  "name": "@zebra/xxx",
  "version": "0.0.1",
  "description": "项目描述",
  "author": "baskwind <baskwind@163.com>",
  "bugs": {
    "url": "https://demo.com/path/to/repo/issues"
  },
  "homepage": "https://demo.com/path/to/demo",
  "keywords": [
    "keywords",
    "keywords"
  ],
  "repository": {
    "type": "git",
    "url": "https://demo.com/path/to/repo"
  },
  "license": "MIT",
  "main": "path/to/index.js",
  "module": "path/to/index.mjs",
  "types": "path/to/index.d.ts"
}

一般通过 npm init 即可生成。

license MIT 的模板

Copyright (C) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

使用时,只需要把 <year> <copyright holders> 换成相应内容即可。

更多许可证:wiki 传送门

README

CDN

  • jsdelivr CommonJS CMD AMD ESM 模块都支持
    • https://cdn.jsdelivr.net/npm/package@version/file
    • https://esm.run/package@version/file
    • https://cdn.jsdelivr.net/gh/user/repo@version/file
  • unpkg.com npm ​镜像
    • https://unpkg.com/package@version/file
  • esm.shESM 模块
    • import xxx from "https://esm.sh/package@version/file"
    • import xxx from "https://esm.sh/gh/user/repo@version/file";
  • bootcdn.cn 国内 npm ​镜像
    • 搜索使用

Read more

Gitlab 搭建

Gitlab 搭建

为什么? 想要自己搭建一个代码仓库无非是以下几点原因: 1. 公司内部项目 2. 自己的项目,但不适合在公网 3. 大部分的 git 仓库虽然有私有服务,但价格都不便宜,甚至不如一台云服务器来的便宜 配置及安装文档 Gitlab * 由于 gitlab 会用到 22 端口端口转发的化就走不了 git clone 的默认配置,且占用内存较高,不推荐使用 docker 进行部署; * 由于 gitlab 自带 nginx 默认情况下会与属主机的 nginx 冲突,因此推荐只使用 gitlab 自带的 nginx 进行端口转发; 最小化配置 # path /etc/gitlab/gitlab.rb external_url 'http://git.

By breeze
NPM 私服

NPM 私服

verdaccio 私服搭建,搭建过程中的一些问题以及解决: * docker compose 启动后,可能会报错:配置找不到,添加 config.yaml 文件到映射的 ./conf 目录即可,config.yaml 具体内容可在官网找到,下方也有最小化配置。 services: verdaccio: image: verdaccio/verdaccio container_name: 'verdaccio' networks: - node-network environment: - VERDACCIO_PORT=4873 - VERDACCIO_PUBLIC_URL=http://npm.demo.com ports: - '10001:4873'

By breeze