Cache busting with CRA React

前端 未结 5 2050
面向向阳花
面向向阳花 2020-12-02 15:22

When I updated my site, run npm run build and upload the new files to the server I am still looking the old version of my site.

Without React, I can see the new ver

5条回答
  •  失恋的感觉
    2020-12-02 15:48

    If your problem is with resources statically referenced in index.html, such as .css files or additional .js files (e.g. configuration files), you can declare a React environment variable, assign a unique value to it and reference it in your index.html file.

    In your build script (bash):

    REACT_APP_CACHE_BUST={e.g. build number from a CI tool} npm run build
    

    In your index.html:

    
    

    The variable name has to start with REACT_APP_. More about environment variables in React: https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables.

提交回复
热议问题