TypeScript编译保存.ts文件两次
问题描述:
我是新来的打字稿,我正在运行一个问题编译。所以我遇到的问题是,当我保存我的.ts文件时,它们会在两个不同的位置编译两次。TypeScript编译保存.ts文件两次
我现在的文件结构是:
-app
|-css (all css files)
|-html (all html files)
|-js (all js files)
|-ts (all ts files)
当我救我的.ts文件被编译并放置在js文件夹,但随后一组新的文件夹格式创建:
-app
|-...
|-js (all js files)
|-app
|-ts (all js files [that were saved ts files])
|-...
我一直在寻找任何有类似问题但找不到任何东西的人。我的package.json文件和文件tsconfig.json如下:
的package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/forms": "0.2.0",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/router": "3.0.0-beta.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.4",
"angular2-in-memory-web-api": "0.0.14",
"bootstrap": "^3.3.6",
"core-js": "^2.4.0",
"d3": "^4.1.1",
"d3tip": "0.5.0",
"d3-tip": "0.6.7",
"d3-tooltip": "0.0.1",
"moment": "^2.14.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.27",
"zone.js": "^0.6.12"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.2.0",
"typescript": "^1.8.10",
"typings": "^1.0.4"
}
}
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "app/js",
"rootDir": "app/ts"
}
}
UPDATE:还是有这个问题。 - 未解决--07/28/2016--
答
好了,所以我想在几个星期前,我解决这个问题,但我错了。不过,我现在已经找到了解决方案。
这个问题实际上并不是我编译js文件的位置。 js文件在第一次编译时会到达正确的位置,但是我使用的是Atom IDE,而atom-typescript有一个默认设置,当它们被保存在Atom编辑器中时,它会编译这些文件。因此,Atom每次保存文件时都会再次编译这些文件。
THE FIX:(告诉原子打字稿不编译)
变化tsconfig.json到:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "./app/js"
},
"compileOnSave": false
}
我们所有做的是添加了 “compileOnSave” 选项并将其设置为false。 因此,告诉原子编译器在保存时不编译。
注意**由于tsc与我的lite-server同时运行,文件仍然在编译时发生变化。
app/ts是ts文件所在的位置 – christian
您说编译生成两个不同位置的文件,它们是什么? –
它在app/js和app/js/app/ts中创建js文件(也将路径/ app和/ app/ts添加到app/js/...,因为它们之前不存在) – christian