我有一个 Ionic 应用程序,它严重依赖条件编译,我根据一组类似于 m4 的工作方式的配置值包含或排除代码块。
为此,我一直在成功使用https://github.com/nippur72/ifdef-loader 。
我现在面临着将此应用程序从 Angular 10 升级到 13(Ionic 5 到 6)。
ifdef-loader 不适用于 Angular 10,但 @angular-dev-kit 的补丁(https://gist.github.com/tristanidoux/892469f2c345bd6c6551eb19c705a016)允许它运行。
此补丁不适用于 Angular 13,因为所有文件都已更改并尽可能多地爬取源代码我还没有看到如何为 Angular 13 创建类似的补丁。
我有以下以 ifdef-loader 文档为模型的 custom.webpack.config.js 文件:
// ifdef-loader config
const opts = {
APP: false,
WEB: true,
DEBUG: true,
version: 3,
"ifdef-verbose": true, // add this for verbose output
"ifdef-triple-slash": true, // add this to use double slash comment instead of default triple slash
"ifdef-fill-with-blanks": true, // add this to remove code with blank spaces instead of "//" comments
"ifdef-uncomment-prefix": "// #code " // add this to uncomment code starting with "// #code "
};
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{ loader: 'ts-loader' },
{ loader: 'ifdef-loader', options: opts }
]
}
]
},
不幸的是,这不起作用,因为 ifdef-loader 似乎没有被调用。
所以三个问题:
我在我的配置中犯了一些明显的错误吗?
有没有人让 ifdef-loader 与 Angular 13 一起工作?如果是这样,怎么做?
或者,是否有其他解决方案可以在 Angular 13 项目中有条件地包含/排除代码块?
任何指针或建议将不胜感激。