GithubHelp home page GithubHelp logo

cjlvscjl123 / requirejs-plugins Goto Github PK

View Code? Open in Web Editor NEW

This project forked from millermedeiros/requirejs-plugins

0.0 2.0 0.0 711 KB

RequireJS Plugins

License: MIT License

JavaScript 100.00%

requirejs-plugins's Introduction

RequireJS plugins

Small set of plugins for RequireJS. Some plugins may also work on other AMD loaders (never tested it).

For more plugins check RequireJS Wiki.

Install

You can use bower to install it easily:

bower install --save requirejs-plugins

Plugins

  • async : Useful for JSONP and asynchronous dependencies (e.g. Google Maps).
  • font : Load web fonts using the WebFont Loader API (requires propertyParser)
  • goog : Load Google APIs asynchronously (requires async! plugin and propertyParser).
  • image : Load image files as dependencies. Option to "cache bust".
  • json : Load JSON files and parses the result. (Requires text! plugin).
  • mdown : Load Markdown files and parses into HTML. (Requires text! plugin and a markdown converter).
  • noext : Load scripts without appending ".js" extension, useful for dynamic scripts.

Other

  • propertyParser : Just a helper used by some plugins to parse arguments (not a real plugin).

Documentation

check the examples folder. All the info you probably need will be inside comments or on the example code itself.

Basic usage

Put the plugins inside the baseUrl folder (usually same folder as the main.js file) or create an alias to the plugin location:

require.config({
    paths : {
        //create alias to plugins (not needed if plugins are on the baseUrl)
        async: 'lib/require/async',
        font: 'lib/require/font',
        goog: 'lib/require/goog',
        image: 'lib/require/image',
        json: 'lib/require/json',
        noext: 'lib/require/noext',
        mdown: 'lib/require/mdown',
        propertyParser : 'lib/require/propertyParser',
        markdownConverter : 'lib/Markdown.Converter'
    }
});

//use plugins as if they were at baseUrl
define([
        'image!awsum.jpg',
        'json!data/foo.json',
        'noext!js/bar.php',
        'mdown!data/lorem_ipsum.md',
        'async!http://maps.google.com/maps/api/js?sensor=false',
        'goog!visualization,1,packages:[corechart,geochart]',
        'goog!search,1',
        'font!google,families:[Tangerine,Cantarell]'
    ], function(awsum, foo, bar, loremIpsum){
        //all dependencies are loaded (including gmaps and other google apis)
    }
);

Removing plugin code after build

r.js nowadays have the stubModules setting which can be used to remove the whole plugin code:

({
    // will remove whole source code of "json" and "text" plugins during build
    // JSON/text files that are bundled during build will still work fine but
    // you won't be able to load JSON/text files dynamically after build
    stubModules : ['json', 'text']
})

Notes about the Markdown plugin

The Markdown plugin was created mainly to be used to compile the markdown files into HTML during the build step, if you set pragmasOnSave.excludeMdown=true it will remove the Markdown.Converter.js and mdown.js files from the build. Example build settings:

({
    baseUrl : './',
    pragmasOnSave : {
        excludeMdown : true
    },
    paths : {
        mdown : 'lib/requirejs/mdown',
        text : 'lib/requirejs/text',
        markdownConverter : 'lib/Markdown.Converter'
    },
    modules : {
        name : 'main'
    }
})

If excludeMdown=true you won't be able to load markdown files dynamically after the build.

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

Miller Medeiros

License

All the plugins are released under the MIT license.

requirejs-plugins's People

Contributors

aaronj1335 avatar cristiano-belloni avatar dimitarchristoff avatar erykpiast avatar millermedeiros avatar rupal9624 avatar thomaswelton avatar

Watchers

 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.