可以使用frontend-maven-plugin节点,已经安装了npm吗?

时间:2016-05-19 17:00:37

标签: javascript node.js maven npm gruntjs

我是使用maven和frontend-maven-plugin的新手。我知道我们可以将此代码添加到pom.xml以运行grunt,例如:

         <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- NB! Set <version> to the latest released version of    frontend-maven-plugin, like in README.md -->
            <version>@project.version@</version>

            <executions>

                <execution>
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <configuration>
                        <nodeVersion>v5.3.0</nodeVersion>
                        <npmVersion>3.3.12</npmVersion>
                    </configuration>
                </execution>

                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <!-- Optional configuration which provides for running any npm command -->
                    <configuration>
                        <arguments>install</arguments>
                    </configuration>
                </execution>

                <execution>
                    <id>npm run build</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <configuration>
                        <arguments>run build</arguments>
                    </configuration>
                </execution>

                <execution>
                    <id>grunt build</id>
                    <goals>
                        <goal>grunt</goal>
                    </goals>
                    <configuration>
                        <arguments>--no-color</arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我实际上在我的服务器上安装了node和npm 例如:node安装在/ opt / app / trss / nodejs下,npm位于/ opt / app / trss / nodejs / npm下这个pom.xml如何使用我的服务器上安装的npm节点?感谢

3 个答案:

答案 0 :(得分:12)

该插件旨在使用节点的本地安装。使用全球安装的版本已requested before,但开发人员的位置是该节点不占用太多空间,只有在丢失时才会下载。

本地安装节点允许未全局安装节点或使用不同版本的开发人员构建项目,而不必执行比mvn clean install更复杂的任何操作。

您可以使用exec plugin运行全局安装的npm版本,然后使用grunt。类似的东西:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
       <execution>
          <id>run-npm-install</id>
          <phase>compile</phase>
          <goals>
             <goal>exec</goal>
          </goals>
          <configuration>
             <executable>npm</executable>
             <arguments>
                <argument>install</argument>
             </arguments>
           </configuration>
        </execution>
        <execution>
          <id>run-grunt</id>
          <phase>compile</phase>
          <goals>
             <goal>exec</goal>
          </goals>
          <configuration>
             <executable>grunt</executable>
             <arguments>
                <argument>--no-color</argument>
             </arguments>
           </configuration>
        </execution>
    </executions>
</plugin>

答案 1 :(得分:0)

这是一个比较老的问题,但是与使用maven-frontend-plugin而不是使用maven-frontend-plugin可能会导致Eclipse做错事情有关。

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                     <lifecycleMappingMetadata>
                       <pluginExecutions>
                         <pluginExecution>
                           <pluginExecutionFilter>
                             <groupId>org.codehaus.mojo</groupId>
                             <artifactId>exec-maven-plugin</artifactId>
                             <versionRange>[1.6.0,)</versionRange>
                             <goals>
                               <goal>exec</goal>
                             </goals>
                           </pluginExecutionFilter>
                           <action>
                             <execute>
                                <runOnIncremental>true</runOnIncremental>
                             </execute>
                           </action>
                         </pluginExecution>
                       </pluginExecutions>
                     </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

答案 2 :(得分:0)

最后,现在可以跳过节点和npm的安装,如下所述:

https://github.com/eirslett/frontend-maven-plugin/issues/768

<execution>
    <id>install node and npm</id>
    <goals>
        <goal>install-node-and-npm</goal>
    </goals>
    <phase>...</phase>
    <configuration>
        <skip>true</skip>
        <nodeVersion>...</nodeVersion>
        <npmVersion>...</npmVersion>
    </configuration>
</execution>