问题
Angular 5 ngtools isn't ignoring all ".spec.ts" files in my production build.
How would I exclude **.spec.ts* but keep any other .ts ?
/(?:.ngfactory.js|.ngstyle.js|.ts)$/
From my webpack.prod.config.js...
module.exports = merge(baseConfig, {
devtool: "source-map",
module: {
rules:
[
{ // AOT mode support for production
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '@ngtools/webpack'
}
]
},
Click here on link example of image to regex101.com
回答1:
If you plan to allow files with .ngfactory.js, .ngstyle.js and .ts extensions, that means you need to match any string ending with these extensions and not ending with .spec.ts.
Use
/^(?!.*\.spec\.ts$).*(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/
See the regex demo.
Details
^- start of string(?!.*\.spec\.ts$)- a negative lookahead that fails the match if there are any 0+ chars other than line break chars, as many as possible (.*) and then.spec.tsat the end of the string ($) immediately to the right of the current location.*- any 0+ chars other than line break chars, as many as possible(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)-.ngfactory.js,.ngstyle.jsor.ts$- end of string.
来源:https://stackoverflow.com/questions/48154817/reg-ex-to-ignore-spec-ts-files-for-aot-angular-5-build