使用typescript开发angular模块并发布npm包(2)

{ "name": "mzc-ng-api", // 这个名字要小写且不能重复,有大写字母会报错 "version": "1.0.2", "description": "个人博客系统,从后台api取数据的angular封装", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/yiershan/MZC-Ng-Api.git" }, "keywords": [], "author": "yiershan <511176294@qq.com> (https://www.jianshu.com/u/8afb7e623b70)", "license": "MIT", "bugs": { "url": "https://github.com/yiershan/MZC-Ng-Api/issues" }, "homepage": "https://github.com/yiershan/MZC-Ng-Api#readme" }

修正下载源

npm config set registry https://registry.npmjs.org/

登录

npm login

如果没有账号就去注册一个吧

发布

npm publish

发布完成立即生效,去npm就能查到并可以下载

使用typescript开发angular模块并发布npm包

使用

新建一个项目安装包

npm i mzc-ng-api

发现很多东西都发布上去了。

使用typescript开发angular模块并发布npm包

而且在开发工作没有智能提示。

完善优化

编译时生成头文件,*.d.ts。

解决编译器提示功能

在tsconfig.json种设置

"declaration": true,

使用typescript开发angular模块并发布npm包

关于tsconfig.json的更多配置可以好好研究研究

指定发布文件

修改

{ "name": "mzc-ng-api", "version": "1.0.2", "description": "个人博客系统,从后台api取数据的angular封装", "main": "index.js", "types": "./index.d.ts", // 添加这个 "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "files": [ // 指定发布文件 "index.js", "index.d.ts", "src/*.js", "src/*.d.ts", "src/**/*.js", "src/**/*.d.ts", "README.md", "LICENSE", "package.json" ], "repository": { "type": "git", "url": "git+https://github.com/yiershan/MZC-Ng-Api.git" }, "keywords": [], "author": "yiershan <511176294@qq.com> (https://www.jianshu.com/u/8afb7e623b70)", "license": "MIT", "bugs": { "url": "https://github.com/yiershan/MZC-Ng-Api/issues" }, "homepage": "https://github.com/yiershan/MZC-Ng-Api#readme" }

更新版本

npm version prepatch

更多操作

# 版本号从 1.2.3 变成 1.2.4-0,就是 1.2.4 版本的第一个预发布版本。 npm version prepatch # 版本号从 1.2.4-0 变成 1.3.0-0,就是 1.3.0 版本的第一个预发布版本。 npm version preminor # 版本号从 1.2.3 变成 2.0.0-0,就是 2.0.0 版本的第一个预发布版本。 npm version premajor # 版本号从 2.0.0-0 变成 2.0.0-1,就是使预发布版本号加一。 npm version prerelease 更新 npm publish

下载下来看看就好多了

使用typescript开发angular模块并发布npm包

封装些脚本。

可以根据自己需求编写更多快捷脚本

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ceee420aa445d91fce0266a6809e8623.html