Message Boards

Liferay AMD Loader in Gradle Theme WAR project

Daniel Yee, modified 3 Years ago.

Liferay AMD Loader in Gradle Theme WAR project

New Member Posts: 2 Join Date: 9/27/19 Recent Posts
References:
  1. https://help.liferay.com/hc/en-us/articles/360018161951-Liferay-AMD-Module-Loader
  2. https://help.liferay.com/hc/en-us/articles/360018161911-Configuring-Modules-for-Liferay-DXP-s-Loaders-
According to Reference 1, it seems like all I have to do is write the define statement and the Module Config Generator creates the config.json file automatically. However, nothing is created when I run deploy.
I get the following error in the browser's developer console:
Error: The following problems where detected while resolving modules:
    · Missing required module 'test'

   
Am I missing something in my steps or how IntelliJ is setup? I've tried adding the JS Module Config Generator Gradle plugin and the JSTranspiler plugin, but those return statuses of SKIPPED when running them.

It would be great to get it working automatically to avoid misconfigurations, but if it's something wrong with the plugins not working correctly, then how do I manually configure the modules? I'm confused by Reference 2 in modifying the bnd.bnd file. My theme doesn't have one.

Steps:
  1. Create new file test.es.js located at /wars/myTheme/src/main/js/test/
  2. In test.es.js, add the AMD define statement:
    Liferay.Loader.define('test',
       function() {
          'use strict';
    
          return {
             hello: function(msg) {
                [i][b]console[/b][/i].log("Hello " + msg);
             }
          };
       }
    );
  3.   In main.js, add the AMD require statement:
    Liferay.Loader.require('test', function(test) {
       test.hello("goodbye");
    }, function(error) {
       [i][b]console[/b][/i].error(error);
    });
  4. Deploy 
Daniel Yee, modified 3 Years ago.

RE: Liferay AMD Loader in Gradle Theme WAR project (Answer)

New Member Posts: 2 Join Date: 9/27/19 Recent Posts
According to Liferay support, this is expected with liferay-amd-loader version 4.x and later. The documentation is incorrect and are being updated.
The recommended route is to use liferay-npm-bundler which is mandatory for 7.2.