保存.ts文件

时间:2016-07-22 15:26:44

标签: typescript angular atom-editor

我是打字稿的新手,我遇到了编译问题。所以我遇到的问题是,当我保存我的.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"
  }
}

更新:仍有此问题。 - 未解决--07/28/2016 -

2 个答案:

答案 0 :(得分:1)

好的,所以几个星期前我想到我解决了这个问题,但我错了。但是,我现在已经找到了解决方案。

实际上问题不在于我的js文件编译的位置。在第一次编译期间,js文件将转到正确的位置,但是我正在使用Atom IDE,并且atom-typescript有一个默认值,它在将文件保存在Atom编辑器时编译文件。因此,每次我保存文件时,Atom都会第二次编译文件。

FIX :(告诉atom-typescript不编译)

将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同时运行,文件仍会在更改时编译。

答案 1 :(得分:0)

"outDir": "app/js"

"rootDir": "app/ts"

分别执行编译,删除"outDir": "app/js"并将rootDir更改为"rootDir": "app/js"