2016-09-20 193 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>