【问题标题】:can frontend-maven-plugin use node, npm already installed?frontend-maven-plugin 可以使用 node,npm 已经安装了吗?
【发布时间】:2016-09-16 17:11:59
【问题描述】:

我是使用 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 例如:节点安装在/opt/app/trss/nodejs下,npm在/opt/app/trss/nodejs/npm下这个pom.xml如何使用节点,npm安装在我的服务器上?谢谢

【问题讨论】:

    标签: javascript node.js maven npm gruntjs


    【解决方案1】:

    该插件旨在使用本地安装的节点。使用全局安装的版本一直是requested before,但是开发者的立场是node不占空间,缺了才会下载。

    本地安装node可以让没有全局安装node或者正在使用不同版本的开发者构建项目,而无需做任何比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>
    

    【讨论】:

    • 任何想法,我如何在这个插件中指定源和目标文件夹。 ?
    【解决方案2】:

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

    【讨论】:

    • 这缺少路径规范。只是添加跳过尝试使用缺少的本地安装
    【解决方案3】:

    这是一个较老的问题,但同样重要的是,这样做而不是使用 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      • 2021-06-06
      相关资源
      最近更新 更多