匹配 *.ts 但不匹配 *.d.ts 的 Webpack 正则表达式测试 [英] Webpack regex test that matches *.ts but not *.d.ts
问题描述
我正在使用 Webpack (2.3.3) 在 TS 中构建我的 Aurelia 应用程序.但是,由于我为 AureliaPlugin (2.0.0-rc.2) 使用了 includeAll
选项,ts-loader (2.0.3) 对没有导出任何输出的 d.ts 文件表示不满.
I am using Webpack (2.3.3) to build my Aurelia app in TS. 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.
这是我对 ts 文件的规则:{ test:/.ts$/, include:/ClientApp/, use: "ts-loader" }
here is my rule for ts files: { test: /.ts$/, include: /ClientApp/, use: "ts-loader" }
我需要更改测试值,使其匹配名为 *.ts 的文件,但 *.d.ts 除外.你能帮我吗?
I need to change the test value in a way that it matches files named *.ts except *.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.
推荐答案
匹配以 .ts
结尾但不匹配 .d.ts
的字符串的正则表达式是
A regex that matches strings with .ts
at the end but not .d.ts
is
/(^.?|.[^d]|[^.]d|[^.][^d]).ts$/
查看正则表达式演示.它是一种 POSIX 风格的表达式,适用于任何正则表达式引擎.
See a regex demo. It is a POSIX style expression that will work with any regex engine.
详情
(^.?|.[^d]|[^.]d|[^.][^d])
- 任一:^.?
- 字符串开头 + 任何可选字符.[^d]
- 一个点和任何字符,但d
[^.]d
- 除了.
和d
之外的任何字符[^.][^d]
- 除了.
之外的任何字符,然后是d
之外的任何字符(这样,我们匹配所有但是.d
)
(^.?|.[^d]|[^.]d|[^.][^d])
- either of:^.?
- start of string + any optional char.[^d]
- a dot and any char butd
[^.]d
- any char but.
andd
[^.][^d]
- any char but.
and then any char butd
(this way, we match all but.d
)
或者,使用基于前瞻的解决方案:
Alternatively, use a lookahead based solution:
/^(?!.*.d.ts$).*.ts$/
参见另一个演示
详情:
^
- 字符串的开始(?!.*.d.ts$)
- 字符串不能以.d.ts
结尾.*
- 任何 0+ 个字符直到.ts$
-.ts
在字符串的末尾.
^
- start of string(?!.*.d.ts$)
- the string cannot end with.d.ts
.*
- any 0+ chars up to the.ts$
-.ts
at the end of the string.
但是,您可以探索此 SO 主题中描述的另一个选项.
However, you might explore another option described in this SO thread.
这篇关于匹配 *.ts 但不匹配 *.d.ts 的 Webpack 正则表达式测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!