hello-publishing-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

typescript模块发布

npm init -y # 生成package.json
tsc --init # 生成tsconfig.json

修改tsconfig.json,

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es6",
    "rootDir": "src",
    "outDir": "dist",
    "sourceMap": true,
    "declaration": true
  }
}

修改package.json

{
  "main": "dist/math.js",
  "typings": "dist/math.d.ts",
  "scripts": {
    "compile": "rm -rf dist && tsc",
    "prepublish": "npm run compile"
  }
}

npm publish 发布模块,会先在dist生成math.js, math.d.ts, math.js.map,只对dist,package,README.md上传,而src不需要。

测试代码:

npm i @types/chai @types/mocha chai mocha -D

在package.json,增加

  "scripts": {
    "test": "mocha --require ts-node/register test/*"
  },

在tsconfig.json,增加

  "exclude": [
    "test"
  ]

否则出现error TS6059: 'rootDir' is expected to contain all source files.

Readme

Keywords

none

Package Sidebar

Install

npm i hello-publishing-ts

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

2.26 kB

Total Files

5

Last publish

Collaborators

  • lbj2014