在Maven中构建Angular 2项目 [英] build angular 2 project in maven

查看:96
本文介绍了在Maven中构建Angular 2项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Maven构建angular2打字稿项目.有没有一种方法可以将npm installng build命令包装在pom.xml文件中?我只想建立那个项目.

I want to build angular2 typescript project using maven. Is there a method to wrap npm install or ng build command inside the pom.xml file? I just want to build that project.

推荐答案

是的.

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

In package.json define a build in scripts, ours - we use webpack - looks like

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

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

Then use com.github.eirslett:frontend-maven-plugin in your 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>

这篇关于在Maven中构建Angular 2项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆