In this tutorial I show how to integrate nodejs with maven using the Maven Frontend Plugin, above is the vid and
below you will find some useful notes.
- 1.
Pre-reqs
-
Have access to an Adobe Experience Manager instance if you want to install the AEM application and test it. The same pom configs shown here can be used for different types of applicationsHave Maven installed, understand how it works and also understand how to use Adobe's archetype, you can watch my video about maven here: Creating an AEM application using Maven and Adobe's archetype
-
- 2.
Creating the base app
-
Create the app using adobe's archetype
mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate "-DarchetypeGroupId=com.adobe.granite.archetypes" "-DarchetypeArtifactId=aem-project-archetype" "-DarchetypeVersion=19" "-DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/" "-DgroupId=co.dlighthouse.aem.firstapp" "-DartifactId=aem-first-app" "-Dversion=0.1.0-SNAPSHOT" "-Dpackage=co.dlighthouse.aem.firstapp" "-DappsFolderName=first-app" "-DconfFolderName=first-app" "-DartifactName=First App Example" "-DcomponentGroupName=First App Example" "-DcontentFolderName=first-app" "-DcssId=first-app" "-DpackageGroup=first-app" "-DsiteName=First App Example" "-DoptionAemVersion=6.4.0"
-
Create the nodejs module inside the multimodule maven project using yeoman
yo aem-application:galen-module co.dlighthouse.aem.firstapp aem-first-app 0.1.0-SNAPSHOT
-
Don't forget to add the submodule to the list of modules inside your parent pom file
<modules> <module>core</module> <module>ui.apps</module> <module>ui.content</module> <module>it.tests</module> <module>it.launcher</module> <module>ui.npm.galen</module> </modules>
-
- 3.
Maven Frontend Plugin
-
The maven Frontend Plugin allows you to integrate nodejs into your build by just adding a few configurations into the POM file.
-
For this, first you need a plugin configuration on your pom file using the group and artifact Id for the frontend plugin, a version and finally a list of executions that would configure a couple of things about the plugin.
<project> ... <build> <plugins> <plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.8.0</version> <executions> ... </executions> </plugin> </plugins> </build> </project>
-
The first execution allows you to set the version for node and npm (you can also use yarn).
... <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <configuration> <nodeVersion>v12.9.0</nodeVersion> <npmVersion>6.10.2</npmVersion> </configuration> </execution> ... </executions> ...
-
The second execution installs or updates the packages given what you’ve configured on the package.json file.
... <executions> ... <execution> <id>npm-install</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>install</arguments> </configuration> </execution> ... </executions> ...
-
Finally we just need one execution for galen, here we need provide the same name of the script that we have inside the package.json file
... <executions> ... <execution> <id>npm-galen</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>run galen</arguments> </configuration> </execution> </executions> ...
-
- 4.
Comentarios
Publicar un comentario