You can avoid the copying process by configuring the Angular CLI to take build directly in the src/main/resources/static folder.
If you are using Angular 6 or above, you can change build output path in the angular.json file-
{
"$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular.io-example": {
"root": "",
"projectType": "application",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "MODIFIED DIST PATH",
...
The modified dist path will be a relative path to your static folder.
If you are using Angular 5 or below, you can do the same in the .angular-cli.json file-
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "angular5-sample"
},
"apps": [
{
"root": "src",
"outDir": "MODIFIED DIST PATH",
...
Example- If your angular source code is in the src/main/webapp folder, then the modified dist path in the outputPath or outDir properties will be- '../resources/static/dist'.
This will create the dist folder directly in the src/main/resources/static folder. To tell SpringBoot that the index.html file is inside the src/main/resources/static/dist folder, you should update the static locations by adding the classpath of the dist folder in the application.properties file.
If you set the outputPath/outDir as '../resources/static' in the above example, then the build files will directly be generated in the src/main/resources/static folder. However, the Angular build process will delete the entire static folder and create a new static folder with the new build files each time you take an Angular build. You will lose any other files present in the static folder. So it is better to have a separate dist folder inside the static folder.
Hope this helps!