What are Build and package managers tools?
After the developers build an app it needs to be deployed on production servers with all its dependencies which were earlier present in a code repository so that is available to the end users.
To do the same we have to package all the applications files and their dependencies into a single movable file. And then we can get that file to the server and run it there. The packaged file is called Artifact. Creating an artifact is also “Building the code”.
Building the code includes compiling and compressing files. Generating 1 single file out of hundreds of files.
We generally don’t deploy artifacts directly on the server. We store it to deploy it multiple times or to have it as a backup.
The storage where we keep the artifacts is called artifact repository. Some of the artifact repositories are “Nexus” and “JFrog Artifactory”.
What Kind of format do these artifacts have?
The artifact file looks different for each programming language. For example, java has the artifacts of format JAR (Java Archive) or WAR file, it includes whole code plus dependencies like spring framework, DateTime libraries etc.
How to Build the artifacts?
These are built using specific tools. Which are specific to the programming language. For example, for Java, it’s Maven or Gradle.
These tools install dependencies and compile and compress your code.
Above video will help you to create your first Java project.
Using the following command for creating a JAR FILE.
How to run the application?
After the artifact is been made and deployed on the fresh server use the following command.
java -jar <name of jar file>
What about JS Applications?
following command is used for installing dependencies .
-> npm install
npm repository is used for dependencies.
Command line tool- npm
npm start -> start the application
npm stop -> stop the application
npm test -> runt the test
npm publish -> publish the artifact
What if the project is using React in the front end and Java in the back end, How to build the artifact then?
We can then build the artifact in two ways:-
1.packaging front end and back end separately(JAR and TAR)
2. creating a common artifact file (JAR)
What if the project is using React in the front end and NodeJs in the back end, How to build the artifact then?
As both are JS libraries we can then build the artifact in two ways:-
1.separate package.json file for frontend and backend.
2. common package.json file
Frontend/React Code needs to be transpiled!
Transpiled means to make your js code browser readable as the browser does not support the latest JS version or other fancy code decorations, like JSX. The code needs to be compressed/minified! Separate tools are there for that — Build tools/Bundlers! An example is “WebPack”.
first install all the dependencies of the project .
-> cd api
-> npm install
Then use the run command
-> npm run build
server.bundle.js name file will be created in the node_moduled folder.
This will be the compiled and compressed code.
Package Frontend Code (when JAVA is the back end)
- Bundle frontend App with Webpack
- Manage dependencies with npm or yarn
- Package everything into a WAR file
Build tools and Docker
just need a repository which supports docker images.