CMD sample

GIT_SHA1=$(git show --format=\"%h\" --no-patch) NODE_ENV=production rollup -c rollup.config.js

package.json

{
  "scripts": {
    "dev": "yarn watch:spa",
    "build": "GIT_SHA1=$(git show --format=\"%h\" --no-patch) NODE_ENV=production rollup -c rollup.config.js",
    "watch": "GIT_SHA1=$(git show --format=\"%h\" --no-patch) NODE_ENV=development OPEN_SPA=0 rollup -c rollup.config.js --watch",
    "watch:spa": "GIT_SHA1=$(git show --format=\"%h\" --no-patch) NODE_ENV=development OPEN_SPA=1 rollup -c rollup.config.js --watch",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
}

./rollup.config.js

import { writeStaticFileAsync } from './scripts/write_static_file_async'

const gitSHA1 = process.env.GIT_SHA1 || 'No process.env.GIT_SHA1'
const buildInfoFilePath = path.join(__dirname, 'front/static/js/common/constants/build-info.js')
writeStaticFileAsync(buildInfoFilePath, `const gitSHA1 = '${gitSHA1}';`)

./scripts/write_static_file_async.js

import fs from 'fs'

export const writeStaticFileAsync = (storageFilePath, text) => {
  fs.writeFile(storageFilePath, text, 'utf8', (err) => {
    if (!!err) console.log(err)
  })
}

Не забудьте добавить создаваемый файл в .gitignore