Description
Description
There should be a way to allow custom properties on the chunk entries in the generated manifest.json.
For instance, when using the integrity attribute on script elements, the value is a base64-encoded hash based on the file contents. This is information that is associated with each chunk and only needs to be calculated once. This could be done during the build step, and put into the manifest.json for the backend to read.
There are some plugins which use file read/write operations to manipulate the manifest.json. This solution is not clean and there should be an API to insert custom things into the chunk entry.
Suggested solution
One could imagine a function (in the vite config and/or the plugin API) that is called for each generated output chunk:
import { defineConfig, type ManifestChunk } from 'vite';
export default defineConfig({
manifest: {
customFields(content: string, chunk: ManifestChunk) {
return {
hashes: {
sha384: generateSha384(content),
sha256: generateSha256(content),
},
};
},
},
});
The resulting output could look like this (example entry from vite docs):
{
"views/foo.js": {
"file": "assets/foo-BRBmoGS9.js",
"name": "foo",
"src": "views/foo.js",
"isEntry": true,
"imports": ["_shared-B7PI925R.js"],
"css": ["assets/foo-5UjPuW-k.css"],
"customFields": {
"hashes": {
"sha384": "...",
"sha256": "..."
}
}
}
}
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.