Coder Social home page Coder Social logo

grunt-umd's Introduction

grunt-umd

Grunt task to surround JavaScript code with the universal module definition.

Usage

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

Add the following line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-umd');

Then configure the task:

grunt.initConfig({
    umd: {
        all: {
            src: 'path/to/input.js',
            dest: 'path/to/output.js', // optional, if missing the src will be used
            template: 'path/to/template.hbs', // optional; a template from templates subdir can be specified by name (e.g. 'umd');
                // if missing the templates/umd.hbs file will be used
            objectToExport: 'library', // optional, internal object that will be exported
            amdModuleId: 'id', // optional, if missing the AMD module will be anonymous
            globalAlias: 'alias', // optional, changes the name of the global variable
            indent: '  ', // optional, indent source code
            deps: { // optional
                'default': ['foo', 'bar'],
                amd: ['foobar', 'barbar'],
                cjs: ['foo', 'barbar'],
                global: ['foobar', 'bar']
            }
        }
    }
});

And finally use it:

grunt umd:all

Templates

The following predefined Handlebars-templates are available:

  • umd - the default template; the template is based on umd/returnExports.js
  • unit - the template that can be helpful to wrap standalone CommonJS/Node modules; it is slightly modified version of umd template; if objectToExport option is not specified then module.exports value will be used by default

The template that should be applied can be specified by template option (e.g. 'umd' or 'unit'). You can create and use your own template (see predefined templates for examples). The path to the template file should be set relative to Gruntfile.

Demo

  1. Install dependencies - npm install
  2. Go to demo - cd demo
  3. Execute demo - grunt

You should see some /output after this. Study Gruntfile.js to understand how it generates.

Contributors

License

MIT. See LICENSE for more info.

grunt-umd's People

Contributors

bcherny avatar bebraw avatar brianjmiller avatar gamtiq avatar jaridmargolin avatar madamovsky avatar paulogaspar7 avatar stephanebachelier avatar

Watchers

 avatar  avatar  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.