首页 文章

typescript不编译目录中的文件

提问于
浏览
0

我有一个小的打字稿项目并创建了tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true
  },
  "files": [
    "./typings/index.d.ts"
  ]
}

两个文件app.ts和hero.ts包含打字稿代码 .

tsc -p . 不会触发任何编译 .

tsc hero.ts app.ts 触发编译 .

我不知道为什么 tsc -p . 不起作用 .

上下文

我用npm安装了打字稿 .

其中tsc ... path_to_project / node_modules / .bin / tsc

我的package.json的依赖项部分

"dependencies": {
    "backbone": "^1.3.3",
    "backbone.localstorage": "^2.0.0",
    "jquery": "^3.2.1",
    "typescript": "^2.3.4"
  },

1 回答

  • 2

    您的文件不是't being compiled because you'已将.tsconfig中的 files 属性设置为

    "files": [
        "./typings/index.d.ts"
      ]
    

    通过使用 files 属性,您告诉编译器只编译这些文件 . 要么完全删除 files 属性,要么添加app.ts和hero.ts文件

    如果排除 files 属性,则编译器默认包括所有typescript文件 .

    此外:

    在命令行中指定输入文件时,将忽略tsconfig.json文件 .

    这就是为什么当你运行 tsc hero.ts app.ts 时,你的文件被编译 .

相关问题