react-build-info is a development utility designed for React projects to automatically inject build-time metadata into the application. It reads the project's `package.json` file to extract the `version` and combines it with the current date/time to generate a `src/buildInfo.ts` (or `.js`) file. This file contains an exported constant `buildInfo` with `buildVersion` and `buildDate` properties, making build information easily accessible within the React application for debugging, support, or display purposes. The current stable version is `0.0.3`. This package is a low-churn utility, receiving updates primarily as needed to maintain compatibility or address specific issues. Its key differentiator is its simplicity and direct file generation approach, avoiding the overhead of more complex build tool plugins.
npm install react-build-infoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `react-build-info` into your React project's `package.json` build script and then consume the generated build information within a React component. This setup ensures that your application always displays the correct version and build timestamp, which is invaluable for debugging and support. Remember to add `"build": "npm version patch && react-build-info && react-scripts build"` to your `package.json` scripts section.
Modify your `package.json` scripts: `"build": "npm version patch && react-build-info && react-scripts build"`
Always prepend version increment commands: `"build": "npm version patch && react-build-info && react-scripts build"`
Use named import syntax: `import { buildInfo } from './buildInfo';`Treat `src/buildInfo.ts` as an autogenerated file. Any custom build info should be handled through other means or by extending the tool.
Ensure `react-build-info` is correctly integrated into your `package.json` build script (e.g., `"build": "react-build-info && react-scripts build"`) and runs successfully.
Verify that `src/buildInfo.ts` was generated correctly. Most importantly, ensure you are using a named import: `import { buildInfo } from './buildInfo';`No dependency data recorded yet.