yueyao-test
v0.0.2
Published
一个测试npm项目
Downloads
4
Readme
##发布一个npm模块 ###如何开发一个NPM模块 初始化
npm init //模块初始化,生成 package.json
###package.json
package.json 位于模块的目录下,用于定义包的属性。
常见字段:
name - 包名。
version - 包的版本号。
description - 包的描述。
homepage - 包的官网 url 。
author - 包的作者姓名。
contributors - 包的其他贡献者姓名。
dependencies - 依赖包列表。如果依赖包没有安装,npm 会自动将依赖包安装在 node_module 目录下。
devDependencies - 项目应用开发环境依赖
repository - 包代码存放的地方的类型,可以是 git 或 svn,git 可在 Github 上。
main - main 字段是一个模块ID,它是一个指向你程序的主要项目。就是说,如果你包的名字叫 express,然后用户安装它,然后require("express")。
bin - 命令行文件
script - 脚本
engines - 运行引擎
keywords - 关键字
常用命令
NPM提供了很多命令,例如install和publish,使用npm help可查看所有命令。
使用npm help <command>可查看某条命令的详细帮助,例如npm help install。
在package.json所在目录下使用npm install . -g可先在本地安装当前命令行程序,可用于发布前的本地测试。
使用npm update <package>可以把当前目录下node_modules子目录里边的对应模块更新至最新版本。
使用npm update <package> -g可以把全局安装的对应命令行程序更新至最新版。
使用npm cache clear可以清空NPM本地缓存,用于对付使用相同版本号发布新版本代码的人。
使用npm unpublish <package>@<version>可以撤销发布自己发布过的某个版本代码。
npm script
package.json
里面可配置 scripts
{
"name": "yueyao-test",
"version": "0.0.1",
"description": "",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "this is start script",
"dev": " gulp dev"
},
"author": "",
"license": "ISC"
}
命令行执行npm start
会输出this is start script
很多gulp / grunt
命令用 npm scripts
代替
###发布
npm publish