插件frontend-maven-plugin
通过插件frontend-maven-plugin执行NPM编译。
- 首先是在jenkins打包的机器上安装node和yarn(或者直接使用npm)。
- 执行yarn config set registry 来进行设置镜像。防止公司只能访问内部网络的npm镜像地址。
- 执行yarn build 来执行NPM编译操作。
<!-- 执行NPM编译 -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<!--JONE的node和yarn的下载地址 不可变动-->
<installDirectory>/usr/soft</installDirectory>
<!-- <installDirectory>target</installDirectory>-->
<skip>${skipBuild}</skip>
<nodeVersion>v8.9.4</nodeVersion>
<npmVersion>5.6.0</npmVersion>
<yarnVersion>v1.3.2</yarnVersion>
<!-- 下载地址欺骗 实际执行构建服务器 -->
<nodeDownloadRoot>http://nodejs.org/dist/</nodeDownloadRoot>
<yarnDownloadRoot>http://github.com/yarnpkg/yarn/releases/download/</yarnDownloadRoot>
</configuration>
<executions>
<!--<execution>-->
<!--<id>install node and yarn</id>-->
<!--<goals>-->
<!--<goal>install-node-and-yarn</goal>-->
<!--</goals>-->
<!--<phase>generate-resources</phase>-->
<!--</execution>-->
<execution>
<id>yarn config set</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>config set registry https://registry.npm.taobao.org</arguments>
</configuration>
</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>
</plugin>