How to configure npm to use maven folder structure and deploy war

I started my first clean front end project. I want to deploy it java / maven. So I created a regular military project:

β”‚   package.json
β”‚   pom.xml
β”‚   tsconfig.json
β”‚   typings.json
β”‚
β”‚
β”œβ”€β”€β”€src
β”‚   └───main
β”‚       β”œβ”€β”€β”€resources
β”‚       └───webapp
β”‚           β”‚   index.html
β”‚           β”‚
β”‚           β”œβ”€β”€β”€app
β”‚           β”‚       app.component.ts
β”‚           β”‚       main.ts
β”‚           β”‚
β”‚           β”œβ”€β”€β”€css
β”‚           β”‚       styles.css
β”‚           β”‚
β”‚           └───WEB-INF
β”‚                   web.xml
β”‚

My problem is how to set the path to index.html / source in relation to the package. Json Since this is an angular / typescript project, there are also some typescript specific things. but I hope to set the "source" path once and for all in the json package ?!

I am also not sure that I want to deploy the material in "webapp" directly, as there are compilation steps. Therefore, any advice on how to structure your front-end project for maven / war deployment is welcome.

+3
source share
1

NPM Maven, frontend-maven-plugin, , , .

, , pom.xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>group.id</groupId>
    <artifactId>artifact-id</artifactId>
    <version>2.0.14-SNAPSHOT</version>

    <name>Artifact Name</name>

    <packaging>war</packaging>

    <!-- Plug-in definition -->
    <build>
        <plugins>
            <!-- frontend-maven plug-in -->
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>0.0.29</version>
                <configuration>
                    <nodeVersion>v5.10.1</nodeVersion>
                    <npmVersion>3.8.6</npmVersion>
                    <installDirectory>target</installDirectory>
                    <workingDirectory>${basedir}</workingDirectory>
                </configuration>
                <executions>
                    <!-- install node & npm -->
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>

                    <!--npm install -->
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>

                    <!-- npm run build -->
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Maven WAR plug-in -->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

, frontend-maven-plugin:

  • NodeJS: v5.10.1;
  • NPM: 3.8.6;
  • NodeJS NPM, (installDirectory). Maven,
  • (workingDirectory), , package.json. , pom.xml, ${basedir};
  • : , , ; , .json script target build, , , , bundle.js:

    "scripts": {
        "build": "browserify src/main/webapp/app.js -o src/main/webapp/modules/bundle.js"
    }
    

    app.js .json typescript.


, Maven WAR. , web.xml.

, Maven , src/main/webapp. , - ( ), , <packagingExcludes>

<!-- Maven WAR plug-in -->
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
        <packagingExcludes>app/**</packagingExcludes>
    </configuration>
</plugin>

.

, . Maven , .

+4

Source: https://habr.com/ru/post/1694217/


All Articles