我想创建一个 TypeScript 库作为可以在 Node.js 中使用的私有 npm 包(包括6.x)
使用 ES6@types
支持和 TypeScript。
该库的目标是扩展Request
类型express
并提供额外的属性。
我创建了一个新的 Node.js 项目并添加了这个tsconfig.json
:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"strict": true,
"types": ["mocha"]
}
}
Run Code Online (Sandbox Code Playgroud)
这些是 的相关部分package.json
:
{
"name": "@myscope/my-lib",
"main": "dist",
"scripts": {
"build": "rm -rf ./dist && ./node_modules/.bin/tsc",
"test": "./node_modules/.bin/mocha test"
},
"private": true,
"dependencies": {
"joi": "11.4.0"
},
"devDependencies": {
"mocha": "^5.2.0",
"express": "^4.16.4",
"@types/express": "^4.16.1",
"@types/joi": "^14.3.0", …
Run Code Online (Sandbox Code Playgroud)