可以前端maven插件使用节点,npm已经安装



我是使用maven和前端maven插件的新手。我知道我们可以将此代码添加到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/nodjs下,npm安装在/opt/app/trss/ndjs/npm下。这个pom.xml如何使用我的服务器上安装的node、npm?感谢

该插件被设计为使用节点的本地安装。以前曾要求使用全局安装的版本,但开发人员的立场是,节点不会占用太多空间,只有在缺少时才会下载。

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

您可以使用exec插件运行您的全局安装版本的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>

最后,现在可以跳过节点和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>

这是一个老问题,但同样重要的是,这样做而不是使用maven前端插件可能会导致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>

相关内容

  • 没有找到相关文章

最新更新