requirejs-plugins

RequireJS Plugins

  • 所有者: millermedeiros/requirejs-plugins
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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.

主要指標

概覽
名稱與所有者millermedeiros/requirejs-plugins
主編程語言JavaScript
編程語言HTML (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2011-10-26 19:05:43
推送於2020-07-06 17:16:20
最后一次提交2015-02-23 15:01:45
發布數4
最新版本名稱v1.0.3 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數0.9k
關注者數43
派生數216
提交數61
已啟用問題?
問題數52
打開的問題數18
拉請求數10
打開的拉請求數13
關閉的拉請求數6
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?