在package.json中configuration本地打印机编译器

编辑 #1 :似乎我有一个工作configuration,所有的改善这个build议是受欢迎的,虽然。 请参阅答案: https : //stackoverflow.com/a/42269408/1155847


原文问题

我目前正在设置我的环境,以便我的package.jsondevDependencies版本将被使用。 什么是一些最好的做法,所以这是“编辑不知情”,最好可以用作npm脚本,例如: npm run tscompile

要清楚的是 – 当使用npm install typescript -g时,我可以使所有的工作都能正常工作,但是我依赖于全局安装的版本,这不是我想要的,因为我们想要在团队中工作并设置在升级之前,每个成员都有特定的打字稿版本,所以我们都在同一页面上。

我目前正在试图设置它像这样 – 然后npm然后抱怨它不认可“node_modules”作为内部或外部命令…我想我也必须通过tsconfig.json到TSC,或者至less给它“工作目录” – 但我甚至无法通过从本地下载的npmcaching启动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" ] } 

好吧,看起来像这样简单(见下文)。 在这里回答,给其他人寻找答案。 或者请让我知道是否有更好的解决scheme

package.jsonconfiguration脚本,如"tsc": "tsc" 。 然后运行npm run tsc,它会使用你在本地安装的tsc版本,并且发现你的tsconfig.json ofcourse。 它不使用你的全球版本 – 因为我卸载了那个 – 只是在命令行inputtsc出错。

例如:

检查回购 *我在哪玩这个。

的package.json

 { "name": "tswithnodejsgettingstarted", "version": "1.0.0", "description": "", "main": "app/index.js", "scripts": { "start": "npm run tsc && node app/index.js", "tsc": "tsc" }, "author": "", "license": "ISC", "devDependencies": { "typescript": "2.1.6" } } 

*回购: https : //github.com/pluralsight-courses/typescript-fundamentals/tree/master/001-GettingStarted