我想使用maven构建angular2 typescript项目。是否有方法将npm install
或ng build
命令包含在pom.xml
文件中?我只想建立那个项目。
答案 0 :(得分:1)
是的,我们这样做。
在package.json
中定义build
中的scripts
,我们的 - 我们使用webpack - 看起来像
scripts": {
"build": "NODE_ENV=production webpack -p --config webpack.production.config.js",
...
然后在POM中使用com.github.eirslett:frontend-maven-plugin
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.26</version>
<executions>
<execution>
<!-- optional: you don't really need execution ids,
but it looks nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v6.2.2</nodeVersion>
<npmVersion>3.9.5</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: The default argument is actually
"install", so unless you need to run some other npm command,
you can remove this whole <configuration> section.
-->
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
答案 1 :(得分:1)
您可以像这样简单地使用。我已经在我的应用程序中完成了此操作。这是最简单的一个。
安装nodejs并使其在类路径中可用。 并全局安装角度CLI。
npm install -g @angular/cli
编写一个简单的脚本 run.sh
npm install
ng build
现在使用maven exec插件来调用脚本。当您调用maven安装/部署时,它会经历整个生命周期并构建您的有角度的项目。
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.2.1</version>
<executions>
<execution>
<id>Build angular using ng</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/build.sh</executable>
</configuration>
</execution>
</executions>
</plugin>