Browse Source

给 Maven 添加了前端 SDK 自动编译流程

dev-mcp
wanghanlin 4 weeks ago
parent
commit
4d60ceaa0c
  1. 2
      .gitignore
  2. 77
      pom.xml
  3. 2
      src/main/resources/static/sdk/chatbot-sdk.min.js.map

2
.gitignore

@ -35,3 +35,5 @@ build/
### VS Code ### ### VS Code ###
.vscode/ .vscode/
/client/node_modules/ /client/node_modules/
/client/node/
/client/dist/

77
pom.xml

@ -16,6 +16,8 @@
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<spring-ai-alibaba.version>1.0.0.4</spring-ai-alibaba.version> <spring-ai-alibaba.version>1.0.0.4</spring-ai-alibaba.version>
<!-- 设置为 true 可跳过前端 SDK 构建,加快后端编译:mvn compile -Dskip.frontend=true -->
<skip.frontend>false</skip.frontend>
</properties> </properties>
<!-- ==================== Maven 多环境 Profile ==================== --> <!-- ==================== Maven 多环境 Profile ==================== -->
@ -186,6 +188,81 @@
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
<!-- ==================== 前端 SDK 构建(client/ → static/sdk/) ==================== -->
<!-- 使用 frontend-maven-plugin 自动安装 Node.js 并编译前端 SDK -->
<!-- 跳过前端构建:mvn compile -Dskip.frontend=true -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.1</version>
<configuration>
<workingDirectory>client</workingDirectory>
<skip>${skip.frontend}</skip>
</configuration>
<executions>
<!-- 第一步:安装 Node.js(仅首次,后续复用 node_modules 缓存) -->
<execution>
<id>install-node-and-npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v20.18.0</nodeVersion>
</configuration>
</execution>
<!-- 第二步:npm install 安装依赖 -->
<execution>
<id>npm-install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- 第三步:npm run build 编译 SDK -->
<execution>
<id>npm-build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- 复制 SDK 构建产物到 Spring Boot 静态资源目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-sdk-to-static</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/main/resources/static/sdk</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/client/dist</directory>
<includes>
<include>chatbot-sdk.js</include>
<include>chatbot-sdk.min.js</include>
<include>chatbot-sdk.js.map</include>
<include>chatbot-sdk.min.js.map</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

2
src/main/resources/static/sdk/chatbot-sdk.min.js.map
File diff suppressed because it is too large
View File

Loading…
Cancel
Save