Comments (2)
Updated the report to highlight why this is broken for both chunkhash and contenthash.
from webpack-plugin-hash-output.
Here's an MVP reproduction of the bug: https://glitch.com/edit/#!/standing-flashy-slouch
If you change the chunk loaded in the HTML from main
to main2
you can see that it works, but otherwise breaks.
There are a couple of ways around this:
- We replaced this branch of code with a check to make sure that
contenthash
is in use for CSS files (which is what we'd want to do anyway). Since we're ok with not running this plugin over those CSS files, this resolved the issue for us.
At the file
// Update the name of the main files
chunk.files.filter(isMainFile).forEach((oldChunkName, index) => {
// PATCHED: Do not run the hashing over CSS files due to the bug described in
// https://github.com/scinos/webpack-plugin-hash-output/issues/29
// We assume that CSS and CSS sourcemaps are using contenthash and do not need to be rehashed anyway.
if (oldChunkName.endsWith('.css') || oldChunkName.endsWith('.css.map')) {
if (oldChunkName.includes(chunk.renderedHash)) {
throw new Error(
'Chunk name included the rendered hash, and it was a .css or .css.map file. Do not use renderedhash with CSS files – use contenthash. See https://github.com/scinos/webpack-plugin-hash-output/issues/29 for details',
);
}
return;
}
const asset = assets[oldChunkName];
const { fullHash, shortHash: newHash } = hashFn(asset.source());
let newChunkName;
if (oldChunkName.includes(chunk.renderedHash)) {
// Save the hash map for replacing the secondary files
nameMap[chunk.renderedHash] = newHash;
newChunkName = oldChunkName.replace(chunk.renderedHash, newHash);
// Keep the chunk hashes in sync
chunk.hash = fullHash;
chunk.renderedHash = newHash;
} else {
// PATCHED: Throw an error in the case where we did not find the rendered hash in the chunk name. We won't be rehashing that.
throw new Error(
'Chunk name did not include the rendered hash, and was not a .css or .css.map file. HashOutputPlugin does not support other types of hashes for assets. See https://github.com/scinos/webpack-plugin-hash-output/issues/29 for details',
);
}
// Change file name to include the new hash
chunk.files[index] = newChunkName;
asset._name = newChunkName;
delete assets[oldChunkName];
assets[newChunkName] = asset;
});
- Apply the fix that @yepitschunked suggested above:
At the file
// Update the name of the main files
chunk.files.filter(isMainFile).forEach((oldChunkName, index) => {
const asset = assets[oldChunkName];
const { fullHash, shortHash: newHash } = hashFn(asset.source());
let newChunkName;
if (oldChunkName.includes(chunk.renderedHash)) {
// Save the hash map for replacing the secondary files
nameMap[chunk.renderedHash] = newHash;
newChunkName = oldChunkName.replace(chunk.renderedHash, newHash);
// Keep the chunk hashes in sync
chunk.hash = fullHash;
chunk.renderedHash = newHash;
} else {
const contentHash =
Object.values(chunk.contentHash).find((hash) => oldChunkName.includes(hash)) || [];
if (!contentHash) {
return;
}
if (nameMap[contentHash]) {
// We've done this hash before. The source map in a file is making the
// newHash different, so replace the same way?
newChunkName = oldChunkName.replace(contentHash, nameMap[contentHash]);
} else {
// Save the hash map for replacing the secondary files
nameMap[contentHash] = newHash;
newChunkName = oldChunkName.replace(contentHash, newHash);
}
}
// Change file name to include the new hash
chunk.files[index] = newChunkName;
asset._name = newChunkName;
delete assets[oldChunkName];
assets[newChunkName] = asset;
});
from webpack-plugin-hash-output.
Related Issues (13)
- vendor bundle not updated correctly HOT 1
- Fails with Webpack 4 HOT 2
- Maximum call stack size exceeded HOT 11
- Hung in infinite loop HOT 4
- When used with source maps, webpack looks for a bundle hash that is actually the source map hash HOT 1
- Loading chunk failed HOT 3
- Usage with devtool: "hidden-source-map" HOT 5
- Output hash must add the hash in the `emit` compiler hook for webpack 3. HOT 2
- 1.3.1 changed the hash,not sync with html-webpack-plugin HOT 6
- 1.3.0 is blocking webpack building
- Webpack 5 migration HOT 1
- plugin doesn't work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack-plugin-hash-output.