留言板

AMD Loader Problem Loading Custom Module in 7.0 GA3 Theme

Paul Allain,修改在7 年前。

AMD Loader Problem Loading Custom Module in 7.0 GA3 Theme

Junior Member 帖子: 77 加入日期: 13-9-3 最近的帖子
Hello,

After looking around for many days at a solution I decided it's time to post a thread about a problem with loading AMD modules in a Liferay theme.

The configuration below shows a custom module but in production it does not load with this error in the console:

Uncaught (in promise) TypeError: a.add is not a function


when I add the following to portal-ext.properties the custom module is loaded and works fine.

minifier.enabled=false
theme.css.fast.load=false
theme.css.fast.load.check.request.parameter=true
theme.images.fast.load=false
theme.images.fast.load.check.request.parameter=true
javascript.fast.load=false
javascript.log.enabled=false
layout.template.cache.enabled=false


If I comment out minifier.enabled=false the error above start showing.

The following is my configuration for loading custom modules in Liferay 7.0 GA3.

src/js/tasks.js
Custom AMD module

define('tasks', [], function () {
    function add(x, y) {
         return (x + y);
    }
    return {
        add: add
    };
});


config.js

Loader.addModule({
    dependencies: [],
    anonymous: true,
    name: 'tasks',
    path: '/o/my-theme/js/tasks'
});


main.js

AUI().ready(
    function () {
        require(['tasks'], function (tasks) {
            console.log('------> ' + tasks.add(10, 10));
        }, function (error) {
            console.error(error);
        });
    }
);


liferay-plugin-package.properties

Liferay-JS-Config=/js/config.js


Note that for example moment.js loads fine in both cases using the same approach.

Any ideas why my custom module is not loading without the development properties enabled?

Thanks in advance.
Paul