frontend-maven-plugin官網地址:https://github.com/eirslett/frontend-maven-plugin
frontend-maven-plugin插件支持在maven中實現前後端項目的統一打包構建,並且不影響本地前端的調試和編譯。
在項目pom.xml中,引入插件:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>src/main/antd</workingDirectory>
<nodeVersion>v10.16.2</nodeVersion>
<!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
<yarnVersion>v1.17.3</yarnVersion>
<!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
<nodeDownloadRoot>https://npm.taobao.org/dist/</nodeDownloadRoot>
<yarnDownloadRoot>https://npm.taobao.org/mirrors/yarn/</yarnDownloadRoot>
</configuration>
</plugin>
注意設置正確的<workingDirectory>,node和yarn或者npm的下載鏈接如果官方的鏈接下載速度很慢的話,可以使用淘寶的鏡像地址。frontend-maven-plugin插件會在maven第一次運行中下載Node和yarn以及install組件,下載成功後,後續maven運行就不會在下載,接着執行yarn build命令,將jsx文件編譯成js + css。