npm插件-建立一个自己的插件步骤

一个简单npm插件的开发步骤如下
1 找个文件夹,命令行里输入:
mkdir i8n-autoinsert
cd i18n-autoinsert
npm init

npm init会要求填写一堆的信息,这些信息会在package.json里体现,例如

{
  "name": "i18n-autoinsert", //插件名,在https://www.npmjs.com里没有的
  "version": "1.0.6", //版本号,每次npm publish 要改下这个版本号
  "description": "it is quit trouble when dev ux need supportmultiple language ,need to write tranlation key in en.json and html ,this plugin is to resolve this problem.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "commander": "^2.11.0"
  },
  "bin":{
    "i18n-autoinsert":"./index.js"
  },
  "author": "rechard",
  "license": "ISC"
}
2 index.js

在i18n-autoinsert项目里建立一个index.js

index.js

#!/usr/bin/env node

console.info('hello world');
3 运行
node index.js

看到控制台输出

hello world

目录i18n-autoinsert里就只有如下

  • index.js
  • package.json
4 发布

到https://www.npmjs.com注册一个账号,注册完后

添加用户

npm adduser

发布自己的插件到https://www.npmjs.com

npm publish
5 使用
npm install -save-dev i18n-autoinsert
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值