Arkantos1
Arkantos1

Reputation: 251

Build files name change - files that are generated from create react app

The build files generated through create react app have different names (hash code) every time.

I would like to give custom names for the generated files.

Is there any possibility to do that?

Upvotes: 12

Views: 17541

Answers (2)

Nithin Thampi
Nithin Thampi

Reputation: 3689

You can change the output filename by customizing the filename property in webpack config -- refer to https://webpack.js.org/guides/caching/

The default implementation is kept like this because, because every time you build an asset, it generates a new name and browsers won't be able to serve a cached response.

If you change the name to a constant you might need to clear the browser cache manually/ disable cache to see your changes immediately. (I think...Applicable only in prod mode as dev mode makes use of Hot module replacement)

Steps to change file name in CRA.

  1. npm run eject This will unwind the hidden configs from CRA and show some additional config folders

  2. Move to the config folder.

  3. Edit file webpack.config.js (Somewhere around line 172 - 180 you can see filename: section where this is defined)

Upvotes: 5

Remi
Remi

Reputation: 5367

Following up to my comment, if you absolutely must change Webpack configuration you can also consider libraries such as:

Upvotes: 0

Related Questions