eirslett / frontend-maven-plugin

"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins." A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.
Apache License 2.0
4.26k stars 870 forks source link

Is it possible to build multiple frontend apps with this plugin? #872

Open parrotcar00 opened 4 years ago

parrotcar00 commented 4 years ago

I have 2 react apps in 2 serparate directories: src/main/app1 and src/main/app2. Is it possible to direct this plugin to build both these apps and copy the respective build output to the static directory separately like index1.html and index2.html?

I'm not sure if I can specify multiple frontend-src-directories in the plugin configuration.

eirslett commented 4 years ago

Yes, that's not a problem. Just have one Webpack/whatever-you-use invocation per app.

petrovichs commented 4 years ago

Hi! I have 2 react apps in 2 directory: src/main/app1 and src/main/app2. Problem: the plugin only works with the last workingDirectory

[INFO] --- frontend-maven-plugin:1.10.0:npm (Build App1) @ my_project_name --- [INFO] Running 'npm run build' in /u01/jenkins/workspace/autodeploy/build/..my_project_name../src/main/app2

.... [INFO] --- frontend-maven-plugin:1.10.0:npm (Build App2) @ my_project_name --- [INFO] Running 'npm run build' in /u01/jenkins/workspace/autodeploy/build/..my_project_name../src/main/app2

My pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.10.0</version>
            <configuration>
                <nodeVersion>v13.7.0</nodeVersion>
                <npmVersion>6.13.7</npmVersion>
                <workingDirectory>src/main/app1</workingDirectory>
            </configuration>
            <executions>
               ......
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>Copy frontend App1</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/my_project_name/app1</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/app1/build</directory>
                                <filtering>false</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.10.0</version>
            <configuration>
                <nodeVersion>v13.7.0</nodeVersion>
                <npmVersion>6.13.7</npmVersion>
                <workingDirectory>src/main/app2</workingDirectory>
            </configuration>
            <executions>
               ....
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>Copy frontend App2</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/my_project_name/app2</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/app2/build</directory>
                                <filtering>false</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>
restapisolutions commented 4 years ago

Hi Petrovichs Works for me like this , I got 2 front end directories , one simply called frontend and the second called admin. Your paths might be different but the config is similar I put a separate configuration in each execution to be able to use 2 workingDirectories. And the maven resources plugin also has 2 executions with different configurations.

<plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>${frontend-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>install-frontend-tools</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${frontend-src-dir}</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>yarn-install-for-Frontend</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${frontend-src-dir}</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>build-frontend</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <arguments>build</arguments>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${frontend-src-dir}</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>install-frontend-tools-for-admin</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>

                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${project.basedir}/admin</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>yarn-install-for-Admin</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${project.basedir}/admin</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>build-frontend-for-admin</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <arguments>build</arguments>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${project.basedir}/admin</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>position-react-build-frontend</id>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${frontend-src-dir}/build</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>

                    </execution>
                    <execution>
                        <id>position-react-build-admin</id>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/admin/build</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>

                    </execution>
                </executions>
            </plugin>