Rendering an environment variable to the browser in a react.js redux production build running in different environments

后端 未结 3 1105
时光取名叫无心
时光取名叫无心 2021-02-09 11:10

The readme of the react redux realworld.io application at https://github.com/gothinkster/react-redux-realworld-example-app says to edit the src/agent.js to change t

3条回答
  •  耶瑟儿~
    2021-02-09 11:34

    Take a look at Immutable Web Apps!

    It is a methodology that creates a separation of concern between index.html and all other static assets:

    1. It treats index.html as a deployment manifest that contains all environment-specific values.

    This is similar to the accepted answer, by including the environment variables directly in the index.html

    window.env={'API_ROOT':'https://conduit.productionready.io/api'}
    

    It also requires that the reference to other static assets are unique and versioned.

    1. It treats javascript bundles as immutable assets that are built once, published once, and used in multiple environments. Allowing the assets to be promoted through environments to production without being modified or moved.

    It honors both the "build, release, run" and "config" principles of 12factor.

    A great benefit of this approach is that it enables atomic live releases by simply publishing index.html.

提交回复
热议问题