简体   繁体   English

匹配 *.ts 但不匹配 *.d.ts 的 Webpack 正则表达式测试

[英]Webpack regex test that matches *.ts but not *.d.ts

I am using Webpack (2.3.3) to build my Aurelia app in TS.我正在使用 Webpack (2.3.3) 在 TS 中构建我的 Aurelia 应用程序。 However, since I am using includeAll option for AureliaPlugin (2.0.0-rc.2), ts-loader (2.0.3) cries about d.ts files that has nothing exported emitting no output.但是,由于我为 AureliaPlugin (2.0.0-rc.2) 使用了includeAll选项,ts-loader (2.0.3) 会抱怨没有任何导出的 d.ts 文件不发出任何输出。

here is my rule for ts files: { test: /\\.ts$/, include: /ClientApp/, use: "ts-loader" }这是我对 ts 文件的规则: { test: /\\.ts$/, include: /ClientApp/, use: "ts-loader" }

I need to change the test value in a way that it matches files named *.ts except *.d.ts.我需要以一种匹配名为 *.ts 的文件的方式更改测试值,但 *.d.ts 除外。 Can you help me please?你能帮我吗?

Note: I see there is already a similar regex question but that one did not work for me.注意:我看到已经有一个类似的正则表达式问题,但那个对我不起作用。

A regex that matches strings with .ts at the end but not .d.ts is匹配字符串末尾为.ts但不.d.ts正则表达式是

/(^.?|\.[^d]|[^.]d|[^.][^d])\.ts$/

See a regex demo .请参阅正则表达式演示 It is a POSIX style expression that will work with any regex engine.它是一种 POSIX 风格的表达式,适用于任何正则表达式引擎。

Details细节

  • (^.?|\\.[^d]|[^.]d|[^.][^d]) - either of: (^.?|\\.[^d]|[^.]d|[^.][^d]) - 以下任一项:
    • ^.? - start of string + any optional char - 字符串开头 + 任何可选字符
    • \\.[^d] - a dot and any char but d \\.[^d] - 一个点和除d任何字符
    • [^.]d - any char but . [^.]d - 除了. and dd
    • [^.][^d] - any char but . [^.][^d] - 除了. and then any char but d (this way, we match all but .d )然后是除d任何字符(这样,我们匹配除.d所有字符)
  • \\. - a literal dot - 一个文字点
  • ts$ - ts at the end of string. ts$ - 字符串末尾的ts

Alternatively, use a lookahead based solution:或者,使用基于前瞻的解决方案:

/^(?!.*\.d\.ts$).*\.ts$/

See another demo另一个演示

Details :详情

  • ^ - start of string ^ - 字符串的开始
  • (?!.*\\.d\\.ts$) - the string cannot end with .d.ts (?!.*\\.d\\.ts$) - 字符串不能以.d.ts
  • .* - any 0+ chars up to the .* - 任何 0+ 个字符直到
  • \\.ts$ - .ts at the end of the string. \\.ts$ - 字符串末尾的.ts

However, you might explore another option described in this SO thread .但是,您可以探索此 SO thread 中描述的另一个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM