Webpack [contenthash] changes on file rename or if file is moved to another directory
See original GitHub issueBug report
What is the current behavior? Contenthash depends on filename and target directory of source file.
If the current behavior is a bug, please provide the steps to reproduce.
- Create a standard webpack config
- Add the following to your webpack config:
mode: 'production',
...
output: {
filename: '[name].[contenthash].js',
clean: true
}
- Run webpack
- Move your entry file to another directory or change it’s filename without modification of the file content.
- Run webpack again
- => Contenthash changed
What is the expected behavior?
Contenthash should only depend on the file content, not on the filename or the directory the file sits in. If the content does not change, the hash should stay the same.
Other relevant information: webpack version: webpack: 5.64.4, webpack-cli: 4.9.1 Node.js version: v14.15.4 Operating System: Windows Additional tools: Typescript
Related Issues: #1479
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Adding Hashes to Filenames - SurviveJS
Including hashes related to the file contents to their names allows to invalidate them on the client-side. If a hash has changed, the...
Read more >CopyWebpackPlugin | webpack
Copies individual files or entire directories, which already exist, to the build directory. Getting Started. To begin, you'll need to install copy-webpack- ...
Read more >Webpack 4: content hash filename? - Stack Overflow
But if I modify the JS file, the [chunkhash] of the CSS file changes too, and vice-versa. There's no reason to invalidate the...
Read more >filename-replace-webpack-plugin - npm package - Snyk
Rename the dist files generated by the Webpack build. advantages. Even if it's not webpack5, you can change the chunk file to any...
Read more >Node.js - Junkman
Plugins play a vital role in outputting your code into files. Quickstart. Create a new directory and move into it: mkdir webpack-4-tutorial cd...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexander-akait @vankop I will do so as soon as I find time to create a presentable minimal example.
Expected, if you need real content hash you should enable https://webpack.js.org/configuration/optimization/#optimizationrealcontenthash, it is
true
by default inproduction
mode, and disabled by default in development mode due perf