Page tree
Skip to end of metadata
Go to start of metadata

Finding light modules

Since all light modules are shared on npm, and include the keyword magnolia-light-module, they are easy to find.

Just visit: https://www.npmjs.com/search?q=magnolia-light-module

Because magnolia developers pay attention to good module design and readme files, its easy to quickly see if there is a module that matches your requirements.

Getting light modules

There are multiple ways to get the modules, we'll cover them in increasing sophistication.

From npm

The packages on npm are ready to use.

The simplest way to grab a package is to run npm install <package name> in your terminal.

(A few warnings will be printed because npm expects a package.json in the directory where "npm install" is run.)

The light module is downloaded into the node_modules directory. Move the light module into your Magnolia resources directory (aka light-modules), and delete the node_modules directory.

From Github

The npmjs.com search results also include links to the github repo (or other source control repository). So you can also clone or download the light module source with the information provided there.

Github contains the complete light module project. Check the readme, it may be necessary to build the project to get or build the required webresources. By convention - they can be built with npm run build in the terminal.

The project can contain other useful files, like tests and demos - that you don't want to include in your production light module. Delete these files when you deploy the module to the Magnolia resources directory. (Typically the _dev and node_modules directories. You can check the .npmignore file for all things that do not belong in the 'built' light module.

Via an npm project

A benefit of having light modules on npm is that you can use its dependency resolution system to grab all the modules you need into your project.

This can be useful on a "light project", a Magnolia project based entirely on light modules. In the most basic version, you can define a package.json file which lists all of the light modules that you want. Anyone can then run npm install to retrieve all of the modules.

Please see this section on light projects for more information and some example projects hosted on github.

Via Maven

For java deveopers, it's easy to retrieve light modules in your Maven based java projects via the maven-frontend-plugin.

https://github.com/eirslett/frontend-maven-plugin

This plugin enables configuring a complete, self contained, frontend build environment and specifying a package.json with the desired light modules as dependencies.

Some example pom.xml configuration:

Fragment from Maven pom.xml
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-clean-plugin</artifactId>
      <configuration>
        <filesets>
          <!-- One directory, one fileset: -->
          <fileset>
            <!-- NPM will install all dependencies in 'node_modules' directory, thus we should add it to the
            clean phase -->
            <directory>node_modules</directory>
          </fileset>
          <fileset>
            <!-- The NPM build tools will copy the Magnolia light modules in there -->
            <directory>light-modules</directory>
          </fileset>
          <fileset>
            <!-- This will also clean the tmp directory of cargo install -->
            <directory>tmp</directory>
          </fileset>
        </filesets>
      </configuration>
    </plugin>
  </plugins>
</build>

<profiles>
  <profile>
    <id>get-light-modules</id>
    <build>
      <plugins>
        <plugin>
          <groupId>com.github.eirslett</groupId>
          <artifactId>frontend-maven-plugin</artifactId>
          <executions>
            <!-- First: install node and npm -->
            <execution>
              <id>install-node-and-npm</id>
              <goals>
                <goal>install-node-and-npm</goal>
              </goals>
              <configuration>
                <nodeVersion>v5.3.0</nodeVersion>
                <npmVersion>3.3.12</npmVersion>
                <!-- optional: where to install node and npm. Defaults to the working directory,
                 but we like it to be in target so that mvn clean removes the install again -->
                <installDirectory>target</installDirectory>
              </configuration>
            </execution>
            <!-- Second: install package.json (i.e. download all given light-modules) -->
            <execution>
              <id>npm-install</id>
              <goals>
                <goal>npm</goal>
              </goals>
              <!-- Optional configuration which provides for running any npm command -->
              <configuration>
                <arguments>install --registry=${npmRegistry}</arguments>
                <installDirectory>target</installDirectory>
              </configuration>
            </execution>
            <!-- Third: run the magnolia-build script to look for light modules in node_modules and copy them over
            light-modules -->
            <execution>
              <id>npm-build</id>
              <goals>
                <goal>npm</goal>
              </goals>
              <configuration>
                <arguments>run build</arguments>
                <installDirectory>target</installDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>
    
package.json
{
  "name": "demo-maven",
  "version": "0.0.1t",
  "private": true,
  "description": "Grab light modules via maven",
  "main": "index.js",
  "scripts": {
    "build": "magnolia-build"
  },
  "dependencies": {
    "calculator-magnolia": "latest"
  },
  "devDependencies": {
    "@magnolia/magnolia-build": "latest"
  }
}




  • No labels