skip to Main Content

I use create-react-app in my React project. when I run, build command it adds hash to file names.

I want to be able to change my media files after build. those that located at static/media.

how can I prevent webpack to add hash to the filenames of svg files.

only svg files. I’m sure they have unique names so, not having hash won’t break the project.

2

Answers


  1. Add the filename template w/o a hashing to the SVG rule:

    {
      test: /.svg$/,
      type: 'asset/resource',
      generator: {
        filename: 'static/media/[name].[ext]', // => dist/static/media/logo.svg
      },
    },
    
    Login or Signup to reply.
  2. You are using create-react-app, and using its workflow. This tool locks you into their webpack configuration

    At the moment, you are importing them and using them that way. This will do magic things on the background like minification or even inlining of the file.

    If you want a predictable URL, place the files inside the public folder and refer to the path of the file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search