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

Creating a Mongo replicaset using docker: Mongo replicaset + Nodejs + Docker Compose

This is a Docker tutorial for creating a Mongo replica set using docker compose and also a couple more containers to experiment with the replica set, above is the vid and below you will find some of the steps followed.
StepsPre-reqsHave node.js installedAnd docker installed (make sure you have docker-compose as well)Create a container for defining configurations for a mongo instanceCreate a container for setting up the replica setCreate a simple node app using expressjs and mongoose (A modified version from the previous video)Create a docker-compose file with the mongo and setup containers and two additional containers for experimenting with the replica setBuild, Run and experiment with your new containers Create a dockerfile for the first mongo container (not really needed but you could configure more stuff if needed)Include container with mongo preinstalled: FROM mongoCreate default/working directory: WORKDIR /usr/src/configsCopy mongo's configurations file into the container
C…

Creating a Docker container for a NodeJs application: Express + Mongo + Docker Compose

This is a Docker tutorial for creating a NodeJs container using expressjs and mongoose, above is the vid and below you will find the steps followed.
StepsPre-reqsHave node.js installedAnd docker installed (make sure you have docker-compose as well)Create an simple node app using expressjs and mongooseModify your container and create a docker-compose fileBuild and Run your new container Create your simple node appInitialize the node appnpm initInstall the dependencies for our appnpm install --save express mongoose Create the database.jsCreate the index.js Create a dockerfileInclude container with node preinstalled: FROM nodeCreate default/working directory: WORKDIR /usr/src/appCopy package.json to workdir and install dependencies (which we will need in this case😊): COPY package.json .RUN npm install Copy the rest of the app (just the index.js file in this case)COPY . .Expose the port required for reaching our expressjs appEXPOSE 3000Add a command to run when this container is star…

Creating Docker containers for Adobe Experience Manager

This is a Docker tutorial for creating a docker image for the Galen framework, above is the vid and below you will find some of the steps followed. Adobe experience manager is a content management system which in a nutshell is an application that allows us to create web sites to be consumed by end users. You might be familiar with other such applications like wordpress or drupal which serves the same purpose A typical deployment would be comprised of two AEM instances, the author instance used for creating and modifying content, the publish instance which serves the content and finally we have a dispatcher which is a static web server used for caching, load balancing and some security purposes. We can configure an AEM instance to work as an author or publish instance by either changing the file name for the jar file java -jar cq-author-450…