Skip to content

Latest commit

 

History

History
executable file
·
150 lines (115 loc) · 6.86 KB

README.md

File metadata and controls

executable file
·
150 lines (115 loc) · 6.86 KB

LMD: Lazy Module Declaration Build Status

Big JavaScript application cause huge startup latency. A 1Mb of JavaScript initializes about ~600-3000ms! without touching any part of DOM. It evals module only when they are required. LMD is inspired by AMD and provides similar module interface

Why LMD? Why not AMD (RequireJS)?

  • Module design is similar to Node.js
    • Actually LMD can work with any JavaScript modules
    • There is no define wrapper!
    • You can use node modules without dirty hacks like typeof exports ? :
    • But you can use old-school function-wrapped-modules. Like IIFE? - Good!
    • You can use strings as string without any "template" plugins
    • You can use JSON file as Object
  • Total and honest isolation
    • LMD package is fully-zero-isolated from globals (globals cant access LMD-pacakge, but LMD can)
    • Modules are isolated from LMD and from each module
    • Modules can be sandboxed (3-party modules, can exports only)
    • Plugins are isolated from LMD and from each module
  • Lazy interpretation and load
    • LMD can load off-package modules (all loaders can do it =)
    • It can interpret(eval) modules when they are required
  • List of depends are located in separate .json file
    • Well... list of 2 deps in file are ok, but 5+ are headache
    • Module is isolated from file system
    • You have to edit only 1 file if module path changes
    • Possible to use dynamic require()
  • Config inheritance
    • Easy to setup development, testing and production builds
  • Build watcher
    • Watcher detects changes in your files and performs rebuild
  • Flexible source
    • Minimal only 288bytes
    • High optimized own code
    • LMD builder performs build-time optimisations
  • Integrated code-coverage and source analytics tool
    • Its easy to enable believe me!
    • No extra servers or movements are required for off-package modules Code-Coverage
  • Transparent localStorage cache
    • Change config and html a bit and voila!
  • require() is not overloaded
    • Overloaded require is the way to mess in source
    • require.css() for css
    • require.js() for js (non LMD-modules)
    • require.async() for async LMD-modules (objects, strings, modules)
  • More
    • Can load CSS
    • Can work with Node.js and Worker environment

What's on the board

  • All builders/loaders stuff bla-bla-bla
  • Build Analyzer (1-click code coverage, depends, startup perfomance)

  • Smart and simple CLI tool

  • GUI for LMD (in development)

Other features

  1. Modules are similar to AMD: there is a require, but no define
  2. LMD does not create globals
  3. LMD is standalone, tiny and flexible (minimal only 288bytes!)
  4. Each function-module can be initialized/evaled on demand (lazy: true)
  5. LMD module is as easy to debug as normal JavaScript file
  6. Build system compresses JavaScript files using UglifyJs
  7. LMD module can define object via return or module.exports or exports as CommonJS Module
  8. Module can be wrapped automatically in builder so you can write your modules as node.js modules (Asynchronous module require)
  9. Starting from version 1.5.2 LMD can require off-package modules "async": true (see Asynchronous module require)
  10. From version 1.6.0 LMD can cache all in-package modules in localStorage "cache": true (see Local Storage cache)
  11. From version 1.6.2 LMD can include off-package css css: true and js-files js: true(for jsonp, cross-origin JS or non LMD modules)
  12. LMD package is possible to run as Web Worker or execute as Node.js script (see Web Worker and Node.js)
  13. LMD works in all modern browsers and in older IE (see Browsers support)
  14. LMD can convert non-LMD modules to LMD to use jquery or any other as in-package LMD module (see LMD module form third-party modules)
  15. LMD can protect your code from 3-party modules (see Modules sandbox)
  16. Code Coverage? - Easy! (see Code coverage)
  17. Ready for production - lmd.js is 100% covered by unit tests see test/README.md for details
  18. SourceMap for all LMD modules (see Source map)
  19. Reach CLI interface

Installing

npm install lmd -g global is prefered for LMD CLI comands.

Getting started with LMD

See Getting Started and Project structure and Docs

LMD Config file

Minimal

{
    "root": "../modules/",
    "output": "../module.lmd.js", // Path are relative to the root parameter
    "modules": {
        "*": "*.js" // use wildcards or specify regex string to grep
    }
}

See LMD Config for more information

Note

  • You can extend config file with another using "extends": "path/to/file.lmd.json" parameter
  • You can also specify module depends by adding "depends" options see Modules depends

Build LMD package from Console

lmd build your_buiild_name

See LMD CLI

Grunt integration and task

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-contrib-lmd

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-contrib-lmd');

See grunt-contrib-lmd for details

Running tests

phantomjs is required to run test via npm test see test for details

--

If you like LMD - ★ it via npm star lmd