Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If multiple assets map to the same output asset name, only one key is included #54

Closed
jdb8 opened this issue May 9, 2019 · 0 comments
Closed
Labels
fixed locally The issue has been resolved locally and will be merged soon

Comments

@jdb8
Copy link

jdb8 commented May 9, 2019

The problem

When emitting files from e.g. file-loader that generate files with the same path, only one key is included in the manifest, when I would expect all keys to be included pointing to the same filename.

E.g. a contrived example: if setting file-loader's name option to a static value such as foo.png, I would expect the manifest.json to look something like:

{
  "animation.gif": "foo.png",
  "cat.jpg": "foo.png",
  "main.js": "main.js",
  "some_image.png": "foo.png"
}

when in reality, it looks more like:

{
  "cat.jpg": "foo.png",
  "main.js": "main.js"
}

Notice how the values other than cat.jpg have been lost. This means that server code expecting to reference some_image.png or animation.gif will have no way to know that they are supposed to map to foo.png.

Again, this is a contrived example since you'd never hardcode an image name like this, but in a more complex example this would occur if two different paths map to the same file with a different name, and we output [contenthash].[ext] or equivalent.

Technical details

Because internally the asset mapping is stored in this.assetNames as a map of hashed filename: original filename, if two assets are output with the same hashed filename, only the first one will be included in the manifest.

It seems like there are two ways this could be solved:

  • switch the order of this.assetNames to use the originalName as the key, mapping to the name from the loader (this matches more closely the final output of the manifest, anyway)
  • keep the structure, but change the this.assetNames values to be an array of original filenames rather than a single one. Less surface area, but would allow multiple manifest keys to map to the same manifest values

My preference would be for the first option since it maps more closely to how I think about this plugin conceptually - using the original, unhashed filenames as our keys, and having our hashed output filenames as the values. Curious if there was a reason I'm missing for having things be the other way round?

Webpack version

4.31.0, node v8.15.1

Webpack config

Using the config in the mocha tests in the repo.

Operating system

Ubuntu 16.04.4 LTS

mxmul added a commit to sharkcore/webpack-assets-manifest that referenced this issue Jun 23, 2020
@webdeveric webdeveric added the fixed locally The issue has been resolved locally and will be merged soon label Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed locally The issue has been resolved locally and will be merged soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants