GithubHelp home page GithubHelp logo

grunt-a2umd's Introduction

a2umd

Converts an AMD module definition to an UMD one.

I like the umd wrappers like grunt-umd, however, I don't like defining my dependencies in a gruntfile.

AMD is a nice way to define your dependencies. As a developer, I always just write AMD modules. As consumers of the modules don't necesarily use AMD, I want a wrapper to be able to use the modules globally.

a2umd converts amd style modules to umd style, using the same concepts as grunt-umd. Since the dependencies are already defined in the AMD style, there is no need to define them again.

So start with an AMD module:

define(['pathA','pathB'],function GlobalName(a,b) {
    return {

    };
});

And use the following grunt config:

{
    'a2umd': {
        all: {
            files: [
                src: 'src/foo.js',
                dest: 'dest/foo.js'
            ]
        }
    }
}

You will end up with a wrapped module:

(function(root, factory) {
    if(typeof define === 'function' && define.amd) {
        define(['pathA','pathB'], factory);
    } else {
        root.GlobalName = factory(root.a,root.b);
    }
}(this, function GlobalName() {
    return {

    };
}));

Specific features

  • leaves the factory function exactly intact (plain copy)
  • extracts dependency paths
  • extracts local dependency names
  • keeps AMD name if given (as first argument in the define())
  • use the factory function name as global name
  • allows to define custom templates instead of the default one

Dependencies

  • esprima: used for parsing the source file and extracting the relevant parts
  • handlebars: used as a template engine to create an UMD style module

grunt-a2umd's People

Watchers

Rikkert Koppes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.