Javascript 前端 Maven 插件可以使用 node,npm 已经安装了吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37329708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can frontend-maven-plugin use node, npm already installed?
提问by zancudo
I am new using maven and frontend-maven-plugin. I understand that we can add this code to pom.xml to run grunt for example:
我是使用 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>
I actually installed node and npm on my server for example: node is installed under /opt/app/trss/nodejs, npm under /opt/app/trss/nodejs/npm how can this pom.xml use the node,npm installed on my server? Thanks
我实际上在我的服务器上安装了 node 和 npm,例如:node 安装在 /opt/app/trss/nodejs 下,npm 安装在 /opt/app/trss/nodejs/npm 下这个 pom.xml 如何使用 node,npm 安装在我的服务器?谢谢
回答by Matt Champion
The plugin has been designed to use a local installation of node. Using a globally installed version has been requested beforebut the developer's position is that node does not take up much space and will only download if missing.
该插件旨在使用本地安装的节点。之前已经要求使用全局安装的版本,但开发者的立场是节点不占用太多空间,只有在缺少时才会下载。
Installing node locally allows developers that have not installed node globally or are using different versions to build the project without having to do anything more complicated than mvn clean install
.
本地安装 node 允许没有全局安装 node 或使用不同版本的开发人员构建项目,而无需做任何比mvn clean install
.
You can use the exec pluginrun your globally installed version of npm and then grunt. Something like:
你可以使用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>
回答by danizen
This is an older question, but it is also relevant that doing this rather than using the maven-frontend-plugin can lead to Eclipse doing the wrong thing:
这是一个较旧的问题,但这样做而不是使用 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>
回答by danizen
Finally, it is now possible to skip node and npm installation as detailed below:
最后,现在可以跳过 node 和 npm 安装,详情如下:
https://github.com/eirslett/frontend-maven-plugin/issues/768
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>