排除链中仅来自一个 Webpack 加载程序的文件

Excluding files from only one Webpack loader in a chain

我目前有一个如下所示的 Webpack 规则:

{ test: /\.tsx?$/, loaders: ['@ngtools/webpack', 'babel-loader', 'angular2-template' ] }

我希望 babel-loader 排除某些文件,基本上只是将它们按原样传递到链下。加载程序的其余部分不应排除这些文件。因此,我无法将文件添加到整个规则的 exclude

我可以在每个加载程序的基础上排除文件吗?如果需要,我愿意编写一些插件代码,尽管开箱即用显然是最理想的。

这与 Angular2 Webpack 问题有关:(我正在尝试解决该问题)https://github.com/angular/angular-cli/issues/2730

虽然我自己没有尝试过,但文档表明这是可能的:将 only 查询传递给 babel-loader,值为 "glob, regex, or mixed array of both".

来源:babel-loader options and Babel options 不要忘记将 properly format the query 值作为字符串,以便选项解析器可以读取它。