title: How can I programmatically generate a file at build-time in Create React App?
body: <p>I'd like for my Create React App to generate a file called <code>VERSION.txt</code> that will end up in my deployed site's <code>public</code> directory as part of its build.</p>
  
  <p>I know I can just create a static file in my repo's <code>public/VERSION.txt</code>, but I want its contents to come from an environment variable. The ENV variable is REACT_APP_COMMIT_REF, which is coming from my Netlify setup. I'd like my CRA to put this variable in <code>public/VERSION.txt</code> (so my React app can easily check it to see if a new version exists), but <a href="https://create-react-app.dev/docs/adding-custom-environment-variables" rel="noreferrer">the docs on environment variables</a> says they're only available in <code>index.html</code> (as well as in any source JS code via <code>process.env</code>).</p>
  
  <p>As a workaround for now I've put it in a <code>meta</code> tag in my <code>public/index.html</code></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;meta name="app-version" content="%REACT_APP_COMMIT_REF%" /&gt;
  </code></pre>
  
  <p>but my app code now has to parse this string and I'd rather just have a <code>public/VERSION.txt</code> to achieve this.</p>
  
  <p>Is it possible for CRA to programmatically generate files at build-time?</p>