Skip to content

A plugin to RequireJS where fix require files that doesn't support AMD pattern like: Backbone, Underscore, Zepto, jQuery, and any other that register a single global var

Notifications You must be signed in to change notification settings

gartz/RequireJS-Wrapper-Plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RequireJS-Wrapper-Plugin

Analytics

This plugin ins deprecated, use RequireJS 2.x shim for same result.

This plugin for RequireJS will give support to load javascript files that doesn't have support to AMD pattern, but declare some global var.

This plugin support RequireJS Optimizer.

Some libs that this plugin will help you:

Configuration

It's very simple to configure:

  • wrapper
  • globals
  • deps

globals config collection

In globals you must declare your include path as key and the generated global as value.

Exemple for underscore:

wrapper: {
  globals: {
    'lib/underscore': '_'
  }
}

Or you can use a function to get the return like:

wrapper: {
  globals: {
    'lib/underscore': function() { return window._.noConflict(); }
  }
}

dependence config collection

Some libs can have dependencies, like Backbone, so this feature is to solve this problem very simple. Because you are working with libs that don't support AMD pattern, you will need to setup their depences in the config file.

Exemple for Backbone:

wrapper: {
  globals: {
    'lib/underscore': '_',
    'lib/backbone': 'Backbone'
  },
  deps: {
    'lib/backbone': ['lib/underscore']
  }
}

Using the require feature

It's very simple, you just need to require your target with plugin wrap, example:

define(['wrap!underscore'], function( _ ) {
  console.debug(_); // returns underscore content
});

Writing your own plugins

Check RequireJS documentation for a basic reference and use other plugins as reference. RequireJS official plugins are a good source for learning.

Also be sure to check RequireJS Wiki.

Author

Gabriel Reitz Giannattasio (Gartz)

License

All the plugins are released under the MIT license.

About

A plugin to RequireJS where fix require files that doesn't support AMD pattern like: Backbone, Underscore, Zepto, jQuery, and any other that register a single global var

Resources

Stars

Watchers

Forks

Packages

No packages published