编写TypeScript npm包的模板

vian ee5d7ec318 chore: npm publish指定特定文件 5 years ago
dist ea61a40d22 build: 默认取消打包成esm、umd文件 5 years ago
src 79a8ec9996 build: init 5 years ago
tests a9f4e85d02 chore: 增加单元测试模块 5 years ago
.eslintignore 79a8ec9996 build: init 5 years ago
.eslintrc.js a9f4e85d02 chore: 增加单元测试模块 5 years ago
.gitignore ee5d7ec318 chore: npm publish指定特定文件 5 years ago
.huskyrc.js ce364b8eab chore: add githook (husky + commitlint + lint-staged) 5 years ago
README.md a9f4e85d02 chore: 增加单元测试模块 5 years ago
commitlint.config.js ce364b8eab chore: add githook (husky + commitlint + lint-staged) 5 years ago
lint-staged.config.js ce364b8eab chore: add githook (husky + commitlint + lint-staged) 5 years ago
package-lock.json ce364b8eab chore: add githook (husky + commitlint + lint-staged) 5 years ago
package.json ee5d7ec318 chore: npm publish指定特定文件 5 years ago
prettier.config.js 79a8ec9996 build: init 5 years ago
rollup.config.js ea61a40d22 build: 默认取消打包成esm、umd文件 5 years ago
tsconfig.json 7443e6c3d3 chore: 设置tsconfig esModuleInterop选项 5 years ago

README.md

本项目是开发TypeScript npm包项目的模板,基于rollup打包,输出可被CommonJS、ESModule识别,并可直接被浏览器script引入的模块。

开始

基于本仓库进行开发,可以fork一个仓库或自行拷贝目录结构。

初始化

npm install

构建

npm run build

代码风格

ESLint + Airbnb config

Prettier

测试

mocha + chai

npm run test

发布

package.json中name名称需要修改为相应包名称。为了将包发到npm私服上,name且必须以“@sc/”开头,如:@sc/test。

发布前应先执行构建指令

注册npm的地址为npm私服地址:

npm config set registry http://192.168.1.90:4873(可使用nrm进行管理)

发布

npm publish

若缺少权限,需要先进行用户验证:

  • 无私服账户: npm adduser
  • 有私服账户 npm login