Preventing Caching in webpack 3.6

64 Views Asked by At

We are currently using webpack 3.6 to build our angular 5 application. However, the way we have our webpack.config.js file, it generates files with the same names always (e.g. main.js). We'd like to have these be uniquely named to prevent caching.

In newer versions of webpack (4.3+) there is a [contenthash] tag that would provide this. However, something breaks when we update to version 4.3 or higher, and we are not able to put the effort forward at this time to resolve it.

Is there a clean way to generate unique names on every build without having to update to a newer version?

1

There are 1 best solutions below

0
On BEST ANSWER

You can use [hash]:

the unique hash generated for every build

Example:

output: {
  filename: "[name].[hash].js"
}

Read more in the docs for output.filename.

Or in the SurviveJS Webpack Book.