npm 发包小记

发包过程

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

添加用户

~ npm adduser
Username:
Password:
Email:

登录

~ npm login
Username:
Password:
Emial:

发布

~ npm publish

取消发布

~ npm unpublish

对于取消发布,仅仅能在发布后的 24 小时内取消。

其他

package.json 文件

这几个字段是需要的:

{
  "name": "matrixchange",
  "version": "1.2.1",
  "description": "炫酷的矩阵运动",
  "main": "index.js",
  "author": "aco <wwsxuan@163.com>",
  "bugs": {
    "url": "https://github.com/acccco/matrixChange/issues"
  },
  "homepage": "https://github.com/acccco/matrixChange",
  "keywords": [
    "matrix",
    "animation"
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/acccco/matrixChange"
  },
  "license": "MIT"
}

一般通过 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 传送门

npm publish

仅仅当 package.json 文件中的 version 变化时才能发布,不然 npm 会认为当前版本没有变动。

README

README 上应写清楚包的使用方式,最好能给个例子。

可以使用 shields.io 生成小图标使用,比如:

image

将网页拉到 Your Badge 标签下,输入相应内容即可生成图标。

关于 ci (持续化部署)

可以在 travis-ci 上注册上自己的 github 账号,然后配置一个 .travis.yml 文件即可完成自动化打包压缩等等。Hexo 博客都是使用这种方式进行更新代码的。

简单例子:

language: node_js
node_js:
 - '8.9'
 - '9.1'

script: make test

services:
    mongodb

更多配置,travis 官方文档

npm 上文件的引用

npm 上的项目是能直接用 cdn 引用的。

https://cdn.jsdelivr.net/npm/{包名}/{路径信息}

所以并不需要讲文件单独发到一个使用者可以访问到的地址。

demo 演示

为了 demo 的演示我们一般上回写个页面,这时就需要有个运行环境,有自己的服务器的话,不是问题,但如果没有 jsfiddle 可以完美解决这个问题。

大概就这么多,想到在补充上。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值