ekanayaka.msl ekanayaka.msl - 2 months ago 66
TypeScript Question

build angular 2 project in maven

I want to build angular2 typescript project using maven. Is there a method for wrap nmp inastall, ng build command inside the pom.xml file? I just want to build that project.

Answer

Yes we do this.

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",
    ...

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