仅安装一次节点,而不是每次使用 Maven 构建

use*_*000 1 maven gruntjs

我需要一位帮助。

我正在使用 grunt 来编译 CSS/JS

我有一个问题,我的节点包是在每次构建时创建的,并且在 Jenkins 中占用了大量空间。我正在使用 Maven 前端插件来实现相同的功能。

我希望节点包最初只创建一次,而不是在每个 Maven 构建中再次创建。

 <id>grunt</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>0.0.26</version>
                        <!-- optional -->
                        <configuration>
                            <workingDirectory>DIR
                            </workingDirectory>
                            <nodeVersion>v4.2.1</nodeVersion>
                            <npmVersion>3.5.1</npmVersion>
                            <installDirectory>node</installDirectory>
                        </configuration>
                      <executions>
                            <execution>
                                <id>node and npm install</id>
                                <goals>
                                    <goal>install-node-and-npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                    <installDirectory>node</installDirectory>
                                </configuration>
                            </execution>
                            <execution>
                                <id>npm install</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                    <installDirectory>node</installDirectory>
                                </configuration>
                            </execution>
                            <execution>
                                <id>grunt build</id>
                                <goals>
                                    <goal>grunt</goal>
                                </goals>
                                <configuration>
                                    <arguments>build</arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
Run Code Online (Sandbox Code Playgroud)

我们正在使用 maven -P grunt 进行构建。它在每个 Maven 构建中创建和安装节点。

为了在全球范围内拥有节点,我正在尝试 maven -P grunt -g ,但它不起作用。

在GitHub组中,我看到有人提到我们不能使用maven前端插件,所以我尝试了maven exec插件。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>prepare-dist-npm-runtime-dependency</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>exec</goal>
        </goals>
        <configuration>
          <executable>node/node</executable>
          <workingDirectory>dist</workingDirectory>
          <arguments>
            <argument>../node/npm/cli.js</argument>
            <argument>install</argument>
            <argument>--production</argument>
          </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

但我看不到它起作用。任何人都可以帮助如何运行 Maven 使其适用于全局节点安装,而不是在每个构建中安装节点?

如果有任何其他建议仅安装节点一次而不是全局安装,我们将不胜感激。

nat*_*les 5

您无法使用Frontend maven plugin. 如果我们查看文档,我们会发现该插件的全部目的是能够在一个隔离的环境中安装 Node 和 NPM,仅用于构建,并且不会影响机器的其余部分。

Node/npm 只会“安装”到您的项目本地。它不会在整个系统上全局安装(并且不会干扰任何已存在的 Node/npm 安装。)

并不是要取代 Node 的开发人员版本 - 前端开发人员仍将在其笔记本电脑上安装 Node,但后端开发人员甚至无需在计算机上安装 Node 即可运行干净的构建。

并不是为了生产用途而安装 Node。Node 的使用旨在作为前端构建的一部分,运行常见的 javascript 任务,例如缩小、混淆、压缩、打包、测试等。

您可以尝试使用两种不同的配置文件运行该插件,一种用于安装,另一种用于安装后的日常使用。在下面的示例中,您应该能够通过运行以下命令来安装 Node 和 NPM:

mvn clean install -PinstallNode
Run Code Online (Sandbox Code Playgroud)

然后每次构建之后:

mvn clean install -PnormalBuild
Run Code Online (Sandbox Code Playgroud)

或者因为normalBuild默认设置为活动状态,只需:

mvn clean install
Run Code Online (Sandbox Code Playgroud)

请注意,安装目标不在日常配置文件中:

<profiles>
    <profile>
        <id>installNode</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>0.0.26</version>
                    <!-- optional -->
                    <configuration>
                        <workingDirectory>DIR</workingDirectory>
                        <nodeVersion>v4.2.1</nodeVersion>
                        <npmVersion>3.5.1</npmVersion>
                        <installDirectory>node</installDirectory>
                    </configuration>
                  <executions>
                        <execution>
                            <id>node and npm install</id>
                            <goals>
                                <goal>install-node-and-npm</goal>
                            </goals>
                            <configuration>
                                <arguments>install</arguments>
                                <installDirectory>node</installDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm install</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>install</arguments>
                                <installDirectory>node</installDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>grunt build</id>
                            <goals>
                                <goal>grunt</goal>
                            </goals>
                            <configuration>
                                <arguments>build</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>normalBuild</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>0.0.26</version>
                    <!-- optional -->
                    <configuration>
                        <workingDirectory>DIR</workingDirectory>
                        <nodeVersion>v4.2.1</nodeVersion>
                        <npmVersion>3.5.1</npmVersion>
                        <installDirectory>node</installDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <id>grunt build</id>
                            <goals>
                                <goal>grunt</goal>
                            </goals>
                            <configuration>
                                <arguments>build</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)