【问题标题】:Regex for matching ts files but not test用于匹配 ts 文件但不测试的正则表达式
【发布时间】:2019-02-13 16:04:42
【问题描述】:

我需要正则表达式来添加到 tsconfig 文件。我正在尝试仅匹配 ts 源文件,而不是测试文件。

试过类似的东西;

  "include": [
    "src/**/*",
    "../../node_modules/@web/common/src/app/views/**/*.ts"
    "../../node_modules/@web/common/src/app/views/**/*.(module|component).ts"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "../../**/*.spec.ts"

但没有运气。

// should match
/main.ts
/hello-world.component.ts

// shouldn't match
/hello-world.component.spec.ts
/app.e2e-spec.ts

【问题讨论】:

  • 您使用特定的编程语言吗?到目前为止,您尝试了什么?
  • Javascript。当前使用“/**/*.ts”
  • 那不是正则表达式。 tsconfig 没有“排除”部分吗? "xx/x.spec.ts" 其中 x 是 *
  • 您尝试过类似"/**/*!(*spec.ts)" 的方法吗?如果您使用的是glob,则有一个ignore section 可以排除文件。
  • "但没有运气" 你确定它不起作用吗?也许它需要从较早的运行中进行一些整理。

标签: regex tsc tsconfig


【解决方案1】:

tsconfig 文件有一个exclude 部分,用于根据模式匹配排除文件。例如:

"include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]

the handbook

【讨论】:

    猜你喜欢
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    相关资源
    最近更新 更多