【问题标题】:Adding compiler options to a stackblitz project向 stackblitz 项目添加编译器选项
【发布时间】:2020-06-08 21:18:12
【问题描述】:

我想将包含以下代码的文件 tsconfig.json 添加到此处的堆栈闪电战示例 https://stackblitz.com/edit/angular-1tbbrn。请问有人做过吗?有人做过吗?

  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "strict": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

【问题讨论】:

  • 这就是我在你的 stackblitz 中看到的......有什么问题?
  • 您缺少ts.config.app.json 文件。其参考位于angular.cli 文件中。
  • @JacopoSciampi 如何添加它们?
  • @KurtHamilton 我想为当前项目的编译器设置严格模式...怎么做?

标签: angular typescript github stackblitz


【解决方案1】:

如果您查看在自己的文件系统上创建的 Angular 项目,您会在 angular.json 中找到这样的条目:

{
  "tsConfig": "tsconfig.app.json"
}

当您查看 tsconfig.app.json 时,您会看到如下内容:

{
  "extends": "./tsconfig.json", // <------ inheritance
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "exclude": [
    "src/test.ts",
    "src/**/*.spec.ts"
  ]
}

所以你可以看到tsconfig.app.json 通过extends 属性继承自tsconfig.json

您已将tsconfig.json 添加到您的项目中,但没有添加app.config.json,因此angular.json 没有引用它。

添加一个继承tsconfig.json 的新文件tsconfig.app.json 应该可以工作。

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2018-04-27
    • 2018-06-19
    • 2023-02-26
    • 1970-01-01
    • 2018-08-30
    相关资源
    最近更新 更多