In development, I want to be able to see the build information (git commit hash, author, last commit message, etc) from the web. I have tried:
npm build
and read from the file (Does not work because fs is also unavailable in browser environment)The only thing left to do seems to be doing npm run eject
and applying https://www.npmjs.com/package/git-revision-webpack-plugin , but I really don't want to eject out of create-react-app. Anyone got any ideas?
Now that you know how to identify a create-react-app, you can use git to pull the project from GitHub. This step entails simply navigating to the project's repository on GitHub, selecting the remote URL from within the green Code dropdown, and then running git clone <project's remote repo url> on your local machine.
When you've successfully deployed the app, open the GitHub repository in your browser. Click the settings tab of the repository and scroll down until you reach the GitHub Pages section and choose the gh-pages branch as the source. Boom, your React application is hosted on GitHub Pages.
On a slight tangent (no need to eject and works in develop), this may be of help to other folk looking to add their current git commit SHA into their index.html as a meta-tag by adding:
REACT_APP_GIT_SHA=`git rev-parse --short HEAD`
to the build script in the package.json and then adding (note it MUST start with REACT_APP... or it will be ignored):
<meta name="ui-version" content="%REACT_APP_GIT_SHA%">
into the index.html in the public folder.
Within react components, do it like this:
<Component>{process.env.REACT_APP_GIT_SHA}</Component>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With