question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Process.env variables inside index.html

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
thien-docommented, Nov 20, 2016

@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.

2reactions
gaearoncommented, Feb 11, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found