匹配* .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$/
参见 regex演示.这是一个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屋!
-