【发布时间】:2017-07-05 06:57:23
【问题描述】:
编辑 #1:似乎我有一个工作配置,但欢迎所有改进它的建议。见答案:https://stackoverflow.com/a/42269408/1155847
原始问题:
我目前正在尝试设置我的环境,以便使用我的package.json 的devDependencies 打字稿版本。有哪些最佳实践,使其“编辑不知道”,最好可以用作 npm 脚本,例如:npm run tscompile?
需要明确 - 使用 npm install typescript -g 时我可以让一切正常工作 - 但是我依赖于全球安装的版本,这不是我想要的 - 因为我们想要在一个团队中工作并开始升级前每个成员都有一个特定的打字稿版本,所以我们都在同一个页面上。
我目前正在尝试像这样设置它 - 但是 npm 然后抱怨它不将“node_modules”识别为内部或外部命令......我想我必须将 tsconfig.json 传递给tsc 也是如此,或者至少给它“工作目录”——但我什至无法从本地下载的 npm 缓存中启动 tsc。
package.json
{
"name": "tswithnodejsgettingstarted",
"version": "1.0.0",
"description": "",
"main": "app/index.js",
"scripts": {
"start": "node app/index.js",
"tscompile": "node_modules/typescript/tsc"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "2.1.6"
}
}
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"sourceMap": true,
"outDir": "app"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
【问题讨论】:
标签: node.js typescript npm visual-studio-code tsconfig