Saturday, May 18, 2024
HomeJavaReact Model Stamping Recipe | Oracle Java Licensed

React Model Stamping Recipe | Oracle Java Licensed


Core Java, Oracle Java, Java Tutorial and Materials, Oracle Java Career, Java Skills, Java Jobs

My view on model numbering is that we must always take the construct time and git SHA of our code and go it by way of to the construct as a model identifier. Then we will simply have a look at any stamped model of our software and discover the place it got here from. To me, that is extra highly effective than stamping an arbitrary launch quantity someplace, whilst a tag within the supply management system.

Let’s say we’ve created this model stamp and we wish to see it in a ReactJS app. Maybe we wish to write it subtly into the DOM someplace so it’s there if we have to verify which model is loaded.

Firstly, we have to push it into the construct course of.

We’d like one thing like this within the bundle.json:

“description”: “BUILD_VERSION“,

After which we will run a command simply earlier than executing the construct on our CI server to go within the precise construct model stamp. Let’s assume it’s in an setting variable known as BUILD_VERSION:

# exchange the placeholder with the precise model

sed -i “s/BUILD_VERSION/${BUILD_VERSION}/g” bundle.json

# then construct

npm run construct

Then we wish to make the outline of the bundle seen to React itself. That is achieved by including a .env file:

REACT_APP_VERSION=$npm_package_description

Which implies we will then use course of.env.REACT_APP_VERSION inside our browser code to choose up the worth that’s entered our bundle by way of the construct course of:<

<span className=”build-version” data-testid=”build-version-test”>

  {course of.env.REACT_APP_VERSION}

</span>

As you’ll be able to see right here, we’ve even tagged this component with an identifier in order that it’s doable for a take a look at to output the model identifier of the app it’s testing.

None of that is laborious. Realizing learn how to put it collectively took a little bit of time. I hope it’s helpful.

Supply: javacodegeeks.com

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments