Direct template loading in AngularWebpackPlugin results in empty component templates
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- angular, typescript, webpack
- 领域
- build-system
调研方向
从 packages/ngtools/webpack/src/resource_loader.ts 中报告所链接的资源加载逻辑开始,然后使用 ng-webpack595 和 ng-webpack598 分支重现该行为。通过检查 dist/repro-webpack-template/main.js 中的 AppComponent_Template,验证 directTemplateLoading=false 时的构建输出。当处理后的模板不再为空且仍包含转换后的 "hello you" 内容时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Command
build
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
18.3.0
Description
A bugfix in webpack 5.96.0 has broken direct template loading.
https://github.com/webpack/webpack/issues/19235#issuecomment-2688250063
When using webpack 5.96.0 or higher, if you set the directTemplateLoading option to false in the AngularWebpackPlugin, component templates end up being empty.
Note: I've said that this is a regression even though technically nothing in the Angular CLI has changed, however if you are updating the Angular CLI regularly, you are probably also updating webpack regularly, so you will encounter this bug.
Minimal Reproduction
Start with this repository: https://github.com/reduckted/repro-webpack-template
This is the setup:
- Contains
AppComponentthat has a template with the content "hello world". - A custom Angular builder is used to modify the webpack configuration and set
AngularWebpackPlugin.options.directTemplateLoadingto false. - A custom loader is to the webpack configuration that replaces all occurrences of "world" with "you" in HTML files.
When this works, the AppComponent's template will end up containing "hello you".
Start by cloning the repository:
git clone https://github.com/reduckted/repro-webpack-template.git
cd repro-webpack-template
Switch to the ng-webpack595 branch (this uses webpack@5.95.0). and build:
git checkout ng-webpack595
npm i
npm run build
Open dist/repro-webpack-template/main.js and search for "AppComponent_Template". You will see that it looks like this:
template: function AppComponent_Template(rf, ctx) {
if (rf & 1) {
_angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵɵtext"](0, "hello you\n");
}
},
This works correctly and has replaced "world" with "you".
Now switch to the ng-webpack598 branch (this uses webpack@5.98.0). and build:
git checkout ng-webpack598
npm i
npm run build
Open dist/repro-webpack-template/main.js again and search for "AppComponent_Template". You will see that it looks like this:
template: function AppComponent_Template(rf, ctx) {},
The template is completely empty.
Exception or Error
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 19.2.0
Node: 22.13.1
Package Manager: npm 11.1.0
OS: win32 x64
Angular: 19.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1902.0
@angular-devkit/build-angular 19.2.0
@angular-devkit/core 19.2.0
@angular-devkit/schematics 19.2.0
@ngtools/webpack 19.2.0
@schematics/angular 19.2.0
rxjs 7.8.2
typescript 5.7.3
zone.js 0.15.0
Anything else relevant?
As @alexander-akait says here: https://github.com/webpack/webpack/issues/19235#issuecomment-2688250063
it was a bug fix in 5.96.0 and unfortunately your code relied on buggy behavior.
Thankfully, the fix is really simple, and @alexander-akait even provided an example of how to fix it. ❤️
Needs to change to:
return `data:application/javascript,export { default } from "${filePath}?${NG_COMPONENT_RESOURCE_QUERY}";`;
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 16 小时 35 分钟
- 30 天内合并 PR
- 176
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/angular-cli 的其他 Issue
-
area: @angular/build gemini-triaged
难度 2/5 1-3 小时 新手友好度 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
难度 2/5 1-3 小时 新手友好度 72/100
angular/angular-cli#33055 · 1 条评论 · 3 个 reaction ·
-
area: @angular/build gemini-triaged
难度 4/5 3-5 天 新手友好度 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 已指派 1 人 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 已指派 1 人 ·
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
vicharanashala/fln#563 ·