12

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?

1
  • 1
    Is there a way to do this without ejecting Commented Oct 1, 2020 at 11:05

2 Answers 2

5

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)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the response. May I know where I can find that file for application generated with create react app?
You need to eject the app first. I'll update the answer to do that
Please note that if you eject the app you will have to start maintaining the webpack configuration yourself and you derive from the standard. medium.com/curated-by-versett/…
0

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

1 Comment

craco doesn't have support for adding __filename to "node" property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.