2016-09-20 84 views
1

我想使用maven构建angular2 typescript项目。有没有一种方法来包装nmp inastall,ng build命令在pom.xml文件中?我只是想建立这个项目。在maven中构建angular 2项目

+0

去看一下官方的[春季引导代码( https://github.com/spring-guides/tut-spring-security-and-angular-js/blob/master/double/ui),它的确使用Maven构建了AngularJS项目。检查它是关于'wro4j'库的'pom.xml',它使用'WebJars','src/main/wro'目录。尽管它使用了Angular'1',你可以通过编辑'wro'文件到合适的依赖关系来切换到'2'版本。 [Angular2依赖项](http://www.webjars.org/npm) – WildDev

回答

1

是的,我们这样做。

package.json定义scripts一个build,我们 - 我们使用的WebPack - 看起来像

scripts": { 
    "build": "NODE_ENV=production webpack -p --config webpack.production.config.js", 
    ... 

然后使用com.github.eirslett:frontend-maven-plugin在你的POM

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