angular / angular/angular-cli

`deploy-url` is not prepended to imported file url when using `file` loader in `esbuild`

未关闭
#32,789 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
angular/build:application area: @angular/build freq1: low gemini-triaged severity3: broken type: bug/fix
主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
14 小时 23 分钟
30 天内合并 PR
162

描述

### Command

build

### Is this a regression?

- [x] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

any webpack-based build

### Description

When using Angular v21 with the new `esbuild` builder, and using a `file` loader configured for certain file types (like SVG) the `--deploy-url` argument passed into the `build` command does not get prepended to the URL returned when importing a file of the said type, and there is no way to configure it to do so.

This was properly working previously with `webpack`, when loading of the SVG assets was configured with a rule like this:
```
{
test: /\.svg$/,
type: 'asset/resource',
generator: {
filename: '[name][hash][ext]',
},
}
```
Looks like with `esbuild` there is no way to achieve the same result, apart from manually adding `deploy-url` to imported URLs in runtime.

### Minimal Reproduction

1. Use `esbuild` application builder
2. Configure angular.json to use `file` loader to import a certain file type:
```
"loader": {
".svg": "file"
},
```
3. Build application using `ng build --deploy-url=/my-deploy-url/`
4. Import some SVG file in the app:
```
import mySvgUrl from './my-image.svg';
```
5. Observe: `mySvgUrl` does not have `/my-deploy-url/` prepended to it

### Exception or Error

No error

### Your Environment

```text
Angular CLI : 21.2.2
Angular : 21.2.4
Node.js : 24.8.0
Package Manager : npm 11.6.0
Operating System : darwin arm64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations │ 21.2.4 │ 21.2.4 │
│ @angular/build │ 21.2.2 │ 21.2.2 │
│ @angular/cdk │ 21.2.2 │ 21.2.2 │
│ @angular/cli │ 21.2.2 │ 21.2.2 │
│ @angular/common │ 21.2.4 │ 21.2.4 │
│ @angular/compiler │ 21.2.4 │ 21.2.4 │
│ @angular/compiler-cli │ 21.2.4 │ 21.2.4 │
│ @angular/core │ 21.2.4 │ 21.2.4 │
│ @angular/elements │ 21.2.4 │ 21.2.4 │
│ @angular/forms │ 21.2.4 │ 21.2.4 │
│ @angular/localize │ 21.2.4 │ 21.2.4 │
│ @angular/platform-browser │ 21.2.4 │ 21.2.4 │
│ @angular/platform-browser-dynamic │ 21.2.4 │ 21.2.4 │
│ @angular/router │ 21.2.4 │ 21.2.4 │
│ rxjs │ 7.8.2 │ 7.8.2 │
│ typescript │ 5.9.3 │ 5.9.3 │
│ vitest │ 4.0.18 │ 4.0.18 │
│ zone.js │ 0.16.0 │ 0.16.0 │
└───────────────────────────────────┴───────────────────┴───────────────────┘
```

贡献指南

打开贡献指南

调研方向

从 esbuild application builder 及其 file-loader 处理开始,以 angular.json 和复现的 `ng build --deploy-url=/my-deploy-url/` 命令作为切入点。验证导入的 SVG URL 是如何生成的,并将其与预期的 deploy URL 行为进行比较;当导入文件的 URL 在无需运行时 workarounds 的情况下包含配置的 deploy URL 时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
build-system, cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。