您可以通过将 Angular CLI 配置为直接在 src/main/resources/static 文件夹中进行构建来避免复制过程。
如果您使用的是 Angular 6 或更高版本,您可以在 angular.json 文件中更改构建输出路径-
{
"$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",
...
修改后的 dist 路径将是静态文件夹的相对路径。
如果您使用的是 Angular 5 或更低版本,您可以在 .angular-cli.json 文件中执行相同操作-
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "angular5-sample"
},
"apps": [
{
"root": "src",
"outDir": "MODIFIED DIST PATH",
...
示例- 如果您的 Angular 源代码位于 src/main/webapp 文件夹中,则 outputPath 或 outDir 属性中修改后的 dist 路径将是- '../resources/static/dist'。
这将直接在 src/main/resources/static 文件夹中创建 dist 文件夹。要告诉 SpringBoot index.html 文件位于 src/main/resources/static/dist 文件夹中,您应该通过在 application.properties 文件中添加 dist 文件夹的类路径来更新静态位置.
如果在上面的例子中将 outputPath/outDir 设置为 '../resources/static',那么构建文件将直接生成在 src/main/resources/static 文件夹中。但是,每次您进行 Angular 构建时,Angular 构建过程都会删除整个静态文件夹并使用新的构建文件创建一个新的静态文件夹。您将丢失静态文件夹中存在的任何其他文件。所以最好在静态文件夹里面有一个单独的 dist 文件夹。
希望这会有所帮助!