Skip to content

Commit

Permalink
fix #2731: put file loader strings in metafile
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Dec 14, 2022
1 parent 70c5729 commit b0a82d3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## Unreleased

* Include `file` loader strings in metafile imports ([#2731](https://github.com/evanw/esbuild/issues/2731))

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`:

```diff
{
...
"outputs": {
"out/image-55CCFTCE.svg": {
...
},
"out/entry.js": {
"imports": [
+ {
+ "path": "out/image-55CCFTCE.svg",
+ "kind": "file-loader"
+ }
],
...
}
}
}
```

## 0.16.6

* Do not mark subpath imports as external with `--packages=external` ([#2741](https://github.com/evanw/esbuild/issues/2741))
Expand Down
5 changes: 5 additions & 0 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4223,6 +4223,11 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
sourceIndex: partRange.sourceIndex,
}

if file.InputFile.Loader == config.LoaderFile {
result.JSONMetadataImports = append(result.JSONMetadataImports, fmt.Sprintf("\n {\n \"path\": %s,\n \"kind\": \"file-loader\"\n }",
helpers.QuoteForJSON(file.InputFile.UniqueKeyForAdditionalFile, c.options.ASCIIOnly)))
}

waitGroup.Done()
}

Expand Down
4 changes: 4 additions & 0 deletions internal/bundler/snapshots/snapshots_loader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,10 @@ d {
"kind": "import-statement",
"external": true
},
{
"path": "out/file-NVISQQTV.file",
"kind": "file-loader"
},
{
"path": "out/copy-O3Y5SCJE.copy",
"kind": "import-statement"
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export interface Metafile {
}
imports: {
path: string
kind: ImportKind
kind: ImportKind | 'file-loader'
external?: boolean
}[]
exports: string[]
Expand Down

0 comments on commit b0a82d3

Please sign in to comment.