我有一个使用Maven和frontend-maven-plugin(com.
github.eirslett)的项目.
当我运行mvn从插件运行安装所有执行时,他们在src / main / webapp根目录中创建一个node_modules,bower_components和node文件夹,其中实际的前端代码是.
问题是,我想安装mvn只执行并在build中创建在build目录中生成的包,而不是在版本化的应用程序代码中,就像它对Java库一样.
有没有办法实现这一目标?
这是我的pom.xml的相关部分:
<build> <directory>build</directory> <outputDirectory>build/classes</outputDirectory> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>UTF-8</encoding> <webResources> <resource> <filtering>true</filtering> <directory>src/main/webapp</directory> <includes> <include>WEB-INF/weblogic.xml</include> </includes> </resource> </webResources> </configuration> </plugin> ... <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>0.0.20</version> <configuration> <workingDirectory>src/main/webapp</workingDirectory> </configuration> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <configuration> <nodeVersion>v0.10.34</nodeVersion> <npmVersion>2.1.11</npmVersion> </configuration> </execution> <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>install</arguments> </configuration> </execution> <execution> <id>bower install</id> <goals> <goal>bower</goal> </goals> <configuration> <arguments>install</arguments> </configuration> </execution> <execution> <id>grunt build</id> <goals> <goal>grunt</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build>
解决方法
可以使用<
installDirectory>配置参数,以选择安装NodeJS的位置.
frontend-maven-plugin会在找到package.json的地方安装node_modules.这就是为什么你需要将你的web资源的副本与package.json一起提供给某个目标/<子路径>.
然后可以通过这种方式配置frontend-maven-plugin:
<plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>0.0.24</version> <configuration> <nodeVersion>v0.11.14</nodeVersion> <npmVersion>2.13.4</npmVersion> <installDirectory>target/<sub-path></installDirectory> <workingDirectory>target/<sub-path></workingDirectory> </configuration> ...