question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack [contenthash] changes on file rename or if file is moved to another directory

See original GitHub issue

Bug 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.

  1. Create a standard webpack config
  2. Add the following to your webpack config:
  mode: 'production',
  ...
  output: {
    filename: '[name].[contenthash].js',
    clean: true
  }
  1. Run webpack
  2. Move your entry file to another directory or change it’s filename without modification of the file content.
  3. Run webpack again
  4. => 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Sebi2020commented, Feb 2, 2022

@alexander-akait @vankop I will do so as soon as I find time to create a presentable minimal example.

1reaction
alexander-akaitcommented, Dec 5, 2021

Expected, if you need real content hash you should enable https://webpack.js.org/configuration/optimization/#optimizationrealcontenthash, it is true by default in production mode, and disabled by default in development mode due perf

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found