Skip to content

Commit b0a82d3

Browse files
committed
fix #2731: put file loader strings in metafile
1 parent 70c5729 commit b0a82d3

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Include `file` loader strings in metafile imports ([#2731](https://github.com/evanw/esbuild/issues/2731))
6+
7+
Bundling a file with the `file` loader copies that file to the output directory and imports a module with the path to the copied file in the `default` export. Previously when bundling with the `file` loader, there was no reference in the metafile from the JavaScript file containing the path string to the copied file. With this release, there will now be a reference in the metafile in the `imports` array with the kind `file-loader`:
8+
9+
```diff
10+
{
11+
...
12+
"outputs": {
13+
"out/image-55CCFTCE.svg": {
14+
...
15+
},
16+
"out/entry.js": {
17+
"imports": [
18+
+ {
19+
+ "path": "out/image-55CCFTCE.svg",
20+
+ "kind": "file-loader"
21+
+ }
22+
],
23+
...
24+
}
25+
}
26+
}
27+
```
28+
329
## 0.16.6
430

531
* Do not mark subpath imports as external with `--packages=external` ([#2741](https://github.com/evanw/esbuild/issues/2741))

internal/bundler/linker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,6 +4223,11 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
42234223
sourceIndex: partRange.sourceIndex,
42244224
}
42254225

4226+
if file.InputFile.Loader == config.LoaderFile {
4227+
result.JSONMetadataImports = append(result.JSONMetadataImports, fmt.Sprintf("\n {\n \"path\": %s,\n \"kind\": \"file-loader\"\n }",
4228+
helpers.QuoteForJSON(file.InputFile.UniqueKeyForAdditionalFile, c.options.ASCIIOnly)))
4229+
}
4230+
42264231
waitGroup.Done()
42274232
}
42284233

internal/bundler/snapshots/snapshots_loader.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,10 @@ d {
12961296
"kind": "import-statement",
12971297
"external": true
12981298
},
1299+
{
1300+
"path": "out/file-NVISQQTV.file",
1301+
"kind": "file-loader"
1302+
},
12991303
{
13001304
"path": "out/copy-O3Y5SCJE.copy",
13011305
"kind": "import-statement"

lib/shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export interface Metafile {
453453
}
454454
imports: {
455455
path: string
456-
kind: ImportKind
456+
kind: ImportKind | 'file-loader'
457457
external?: boolean
458458
}[]
459459
exports: string[]

0 commit comments

Comments
 (0)