【问题标题】:Excluding node_module when using include in tsconfig.json?在 tsconfig.json 中使用 include 时排除 node_module?
【发布时间】:2019-09-17 16:43:59
【问题描述】:

我看到很多人在他们的tsconfig.json 中排除了node_modules。 我正在使用具有特定文件夹模式的 include。我还需要排除node_modules 吗?没有编译成 JS 的第三方库(即作为 TS 包含在我的项目中)呢?

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "declaration": true,
    "declarationDir": "builds",
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "jsx": "preserve",
    "jsxFactory": "Vue",
    "lib": ["dom", "dom.iterable", "esnext", "scripthost"],
    "module": "esnext",
    "moduleResolution": "node",
    "paths": {
      "@/*": ["*"]
    },
    "sourceMap": true,
    "strict": true,
    "target": "esnext",
    "types": ["jest", "node", "vuetify", "webpack-env"],
    "typeRoots": ["node_modules/@types"]
  },
  "include": [
    "codes/**/*.ts",
    "codes/**/*.tsx",
    "shims/**/*.ts"
  ]
}

【问题讨论】:

    标签: typescript node-modules tsconfig


    【解决方案1】:

    排除node_modules 的原因是你的编译器独立于库,因为任何包都应该编译为JS。如果一个包没有编译版本,我会认为它不安全。

    【讨论】:

    • 不使用include 仅足以排除node_modules
    • 为什么说不安全?
    • @geeko 因为如果它没有被编译,开发者会将编译委托给这个库的用户。但他不能。从那里我可以得出结论,这样的开发人员不是专业人士,我不能依赖他/她编写的库。
    • 谢谢。我的第一条评论中的问题怎么样?
    • @geeko 很抱歉没有注意到。绝对够用,你可以用include。这个想法是从编译器中排除node_modules。既可以排除node_modules,也可以不包含在include: [...]中。
    猜你喜欢
    • 2016-07-28
    • 1970-01-01
    • 2016-06-09
    • 2022-08-05
    • 1970-01-01
    • 2018-03-27
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多