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?
So, turns out there is no way to achieve this without ejecting, so the workaround I used is:
1) in package.json, define a script "git-info": "git log -1 --oneline > src/static/gitInfo.txt"
2) add npm run git-info
for both start and build
3) In the config js file (or whenever you need the git info), i have
const data = require('static/gitInfo.txt')
fetch(data).then(result => {
return result.text()
})