我是新使用 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如何使用我服务器上安装的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>
最后,现在可以跳过 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>
这是一个较旧的问题,但这样做也相关,而不是使用 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>
来自@Matt Champion提到的线程。这是一个工作示例:
手动下载
node-v20.15.0-linux-x64.tar.gz
npm-10.7.0.tgz
,并将它们放置在某处:(注意节点的tar.gz必须放置在嵌套的vXX.YY.Z文件夹下)
home/
└── <xxx-user>/
└── temp/
├── v20.15.0/
│ └── node-v20.15.0-linux-x64.tar.gz
└── npm-10.7.0.tgz
然后在
pom.xml
中指定下载文件的路径:
...
<configuration>
<nodeVersion>v20.15.0</nodeVersion>
<npmVersion>10.7.0</npmVersion>
<nodeDownloadRoot>file:///home/<xxx-user>/temp/</nodeDownloadRoot>
<npmDownloadRoot>file:///home/<xxx-user>/temp/</npmDownloadRoot>
</configuration>
...
就是这样,应该可以正常
mvn package