Reg ex to ignore .spec.ts files for AOT angular 5 build

让人想犯罪 __ 提交于 2019-12-11 08:02:04

问题


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.ts at 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.js or .ts
  • $ - end of string.


来源:https://stackoverflow.com/questions/48154817/reg-ex-to-ignore-spec-ts-files-for-aot-angular-5-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!