Updating version-numbers is always quite tedious especially if you have to do it on multiple pages of your app.
A neat way to overcome this issue is to use the version-number from your package.json
file.
Therefor we need to import the package.json
in our next.config.js
.
const { version } = require('./package.json')
module.exports = {};
Next we need to export the version as an environment variable.
const { version } = require('./package.json')
module.exports = {
env: {
version
};
};
Now you can access it like every environment variable with process.env.version
.
This could look like this.
export function NavBar() {
return (
<div>
<p>Version number is {process.env.version}</p>
</div>
)
}