解决一键打包前端后端
使用maven插件frontend-maven-plugin , 可通过maven直接打包前端.最新版可到下载
关于该插件如何配置使用,建议直接去看官方github。在前端模块中,配置pom.xml,配置好后,再使用maven打包项目时,就会将前端后端模块一起全部打包生成jar包。
具体的代码如下:
```html/xml
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<!-- 检查是否安装node npm -->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<!-- 执行脚本,删除node_modules和package-lock.json -->
<execution>
<id>npm run clean</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run clean</arguments>
</configuration>
</execution>
<!-- npm install -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install --registry=https://registry.npm.taobao.org</arguments>
</configuration>
</execution>
<!-- build 之后复制文件到 src/main/resource/static 下 -->
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build-copy</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v10.16.3</nodeVersion>
<npmVersion>6.11.3</npmVersion>
<!-- node安装路径 -->
<installDirectory>${build.node.path}</installDirectory>
<!-- 前端代码路径 -->
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
# 测试

在最外层执行mvn clean install或者双击package、install两个命令也可以,
# 生成的jar

生成的包可以用于直接运行不需要单独再运行前端。
# 其他
欢迎有问题及时交流~
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多交流