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
JS hash fails to change when asset URL changes #3415
Comments
Another important test case for a reimplemented hashing algorithm. |
This also impacts modules containing With assets, you can kinda work around it with |
A workaround that seems to work for me is to add a hash of the asset's source as a JS comment together with return `export default import.meta.ROLLUP_FILE_URL_${this.emitFile({
type: 'asset',
source: await fs.readFile(realId),
name: basename(realId),
})}`; Do this instead: import {createHash} from 'crypto'
// ...
const source = await fs.readFile(realId)
const referenceId = this.emitFile({
type: 'asset',
source,
name: basename(realId),
})
const hash = createHash('sha256').update(source).digest('hex').slice(0, 8)
return `export default import.meta.ROLLUP_FILE_URL_${referenceId}; /* asset-hash:${hash} */` Rollup will now consider the importing JS module's source as being different since the comment depends on the asset source hash, causing a different JS hash (which is what we want). The JS comment is stripped by minification later (if using). |
Fix at #4543 |
This issue has been resolved via #4543 as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4543 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4543 as part of rollup@3.0.0. You can test it via |
In this demo, both
src1
andsrc2
are built. The only difference between the two is the content ofsome-asset.txt
.Expected Behavior
The hash of both the JS and asset is different between builds, since the JS imports the asset, the content of its file has changed.
Actual Behavior
Only the hash of the txt file changes.
The text was updated successfully, but these errors were encountered: