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



我需要一个帮助。

我正在使用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>

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

对于全局节点,我正在尝试maven -P grunt -g,但它不工作。

在GitHub群里,我看到有人说我们不能用maven前端插件,所以我尝试了maven exec plugin .

<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>

但是我看不出它在工作。谁能帮助如何运行maven,使其为全局节点安装工作,而不是安装节点与每个构建?

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

您不能使用Frontend maven plugin全局安装Node或NPM。如果我们看一下文档,我们会发现这个插件的全部目的是能够在一个孤立的环境中安装Node和NPM,只用于构建,而不影响机器的其余部分。

Node/npm只会在本地"安装"到你的项目。它不会全局安装在整个系统上(它不会干扰))

不是为了取代开发者版本的Node - frontend开发人员仍然会在他们的笔记本电脑上安装Node,但是后端开发人员甚至不需要在他们的设备上安装Node就可以运行干净的构建电脑。

不意味着安装Node用于生产使用。Node的使用情况为作为前端构建的一部分,运行常见的javascript任务如缩小,混淆,压缩,包装,测试等。

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

mvn clean install -PinstallNode

之后的每一个build:

mvn clean install -PnormalBuild

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

mvn clean install

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

<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>

最新更新