Supported modules

Mikhail Davydov edited this page Dec 17, 2013 · 5 revisions

By default LMD supports all these modules

Module - functions

CommonJS/Modules

Default module type for LMD.

// @globals require module exports
// CommonJS Module exports
// or exports.feature = function () {}
module.exports = function(message) {
    return message.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};

Module as function declaration

This format of module is deprecated. Use CommonJS/Modules instead.

function main(require) {
    var print = require('depA'),
        i18n = require('i18n'),
        $ = require('$'); // grab module from globals: LMD version 1.2.0

    var text = i18n.hello +  ', lmd';

    print(text);

    $(function () {
        $('#log').text(text);
    });
}

Module as function expression

This format of module is deprecated. Use CommonJS/Modules instead.

(function (require/*, exports, module*/) {
    var escape = require('depB');
    return function(message) {
        console.log(escape(message));
    }
})

Note:

  • CommonJS module will be wrapped by builder (function (require, exports, module) {\n%code%\n})
  • you can require CommonJS off-package modules by declaring one of flags async_plain or async_plainonly

Module - objects

For config, i18n and other resources

{
    "hello": "Привет"
}

Module - string

For templates

<i class="b-template">${content}</i>

Module - shortcuts

See Shortcuts

AMD modules

See AMD modules