Ir al contenido principal

Integrating Nodejs and Maven using The Maven Frontend Plugin

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. 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 applications
      Have 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. 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. 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. 4.

Comentarios

Entradas populares de este blog

How to copy files from and to a running Docker container

Sometimes you want to copy files to or from a container that doesn’t have a volume previously created, in this quick tips episode, you will learn how. Above is the vid and below you will find some useful notes. 1. Pre-reqs Have Docker installed 2. Start a Docker container For this video I will be using a Jenkins image as an example, so let’s first download it by using docker pull docker pull jenkins/jenkins:lts ...

How to create an AEM component using Reactjs

In this tutorial, I will show how to use use Adobe's archetype to create an AEM application with React.js support and also how to add a new React.js component so that it can be added into a page, above is the vid and below you will find some useful notes. In the second part we will see how to configure the Sling Model for the AEM React component. 1. Pre-reqs Have access to an Adobe Experience Manager instance. You will need aem 6.4 Service Pack 2 or newer. Have 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....