Process.env variables inside index.html
See original GitHub issueI’ve read the docs thoroughly as well as issues here and haven’t found such a suggestion.
How about injecting the process.env values to index.html too, just like PUBLIC_URL is being injected?
It’s useful in cases you want to must embed variables (like API keys) in a script tag, e.g. when using react-google-autocomplete and you have to put the following in index.html:
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=%SOME_ENV_VARIABLE%&libraries=places"/>
I know I can do it by ejecting and adding parameters to webpack config, but I thought there should be a better way to perform this without ejecting.
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How do you reference a process.env variable in HTML <script ...
I've access process in webpack.config by 'process.env.NODE_ENV.' Also, I have accessed process.env in another API call in a .js file. The ...
Read more >Can't access "process.env" variables in index.html or ... - GitHub
How can i get / access webpack ENV (process.env) variables during process time (not runtime in browser) ? the webpack.DefinePlugin(.
Read more >[Tips] How to Access Environment Variables Stored in .env ...
My current project required to embed Google Analytics tags in React project's index.html for two different environments, ...
Read more >Replace Environment Variables In Your Index.html - Medium
Configuration is in place, variable has been added, we just have now to implement the script. Basically, what it does, it finds all...
Read more >How Can I Access Environment Variables in My Static Website?
Then in your html or js files you can access the variables using the process.env. prefix. Like this. <html> <body> hello </body> ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gaearon do you mean something like this: https://github.com/dvkndn/create-react-app/commit/ca8e0c557b409b929b6323861f625aa2e321234b
If so I can make one. The above is just idea, I will add for config.prod.js and do some test before making a PR.
This was implemented in https://github.com/facebookincubator/create-react-app/pull/1440.