Sitemap

Build Angular Project using ANT

2 min readMar 30, 2023

--

Introduction

Commonly we use ng commands to build angular project. Thats pretty straight forward. If you want to automate the build one approach we can use apache ant script. Here is the the sample script which i used in my project. I have one legacy system running on tomcat. So my requirement is in one build file I have build all three applications together then script will copy the files to tomcat webapps folder.

Get Sathishkumar’s stories in your inbox

Join Medium for free to get updates from this writer.

Ant Build for Angular app

<?xml version="1.0" encoding="UTF-8"?>
<project name="eclipse-ui">
<property name="project-name" value="${ant.project.name}" />
<property name="build-path" value="dist" />
<property name="dest-path" value="/Applications/projects/deploy" />
<target name ="install">
<echo> Npm install</echo>
<exec executable="npm" failonerror="true">
<arg value="install" />
<arg value="--force" />
</exec>
</target>
<target name="clean">
<delete file="dist" />
<delete file="${build-path}/${project-name}.zip" />
<delete file="${dest-path}/${project-name}.zip" />
<delete file="${dest-path}/${project-name}" />
</target>
<target name ="test">
<echo> Angular unit testing</echo>
<exec executable="ng" failonerror="true">
<arg value="test"/>
<arg value="--include='src/app/workflow-data/workflow-data.component.spec.ts'" />
</exec>
</target>
<target name ="build_prod">
<echo>Building Angular Prod</echo>
<exec executable="ng" failonerror="true">
<arg value="build"/>
<arg value="--prod"/>
</exec>
</target>
<target name ="build">
<echo>Building Angular Local</echo>
<exec executable="ng" failonerror="true">
<arg value="build"/>
</exec>
</target>
<target name="zip">
<zip destfile="${build-path}/${project-name}.zip" basedir="${build-path}/${project-name}" />
</target>
<target name="copy">
<copy file="${build-path}/${project-name}.zip" todir="${dest-path}"/>
</target>
<target name="deploy">
<unzip src="${dest-path}/${project-name}.zip" dest="${dest-path}/${project-name}/"/>
</target>
<target name="clean-and-build" depends="clean,build,zip,copy,deploy" />
</project>

I have added some unit test script running for angular. This build script worked very well. Actually my application is SAAS model so we didn’t used the CI/CD pipeline. You want to automate completely we can setup CI/CD pipeline to do it.

--

--

Sathishkumar
Sathishkumar

Written by Sathishkumar

Technical Lead, We will do design and develop a project from scratch. We do Python, Java, PHP development.