I'm using webpack (V 1.13.2) to bundle my webapp + ReactJS.
I'd like to pass the current commit SHA to the js.
Getting the current commit SHA is straightforward, but I couldn't figure out how to pass it the to js file.
I tried to change the output js file and chain the commit SHA to it:
output:{
path: distPath,
publicPath: '/',
filename: "client.min.js?" + COMMIT_SHA
},
But the webpack won't bundle it.
I also tried to use string-replace-loader like the following:
webpack.config.js:
{
test: /\.jsx?$/,
loader: 'string-replace-loader',
query: {
search: 'COMMIT_SHA_ANCHOR',
replace: VERSION
}
},
client.js:
var commit = 'COMMIT_SHA_ANCHOR';
but I get a syntax error (it creates a new line before closing the string):
Unterminated string constant (34:13)
var commit = '4820fa5de22d3463a0ca39c1d4067a62800d1d07
| ^
35 | ';
What is the best way (if exists) to pass the commit SHA to js?