You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.mdown 4.0 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # RequireJS plugins
  2. Small set of plugins for [RequireJS](http://requirejs.org). Some plugins may
  3. also work on other AMD loaders (never tested it).
  4. For more plugins check [RequireJS Wiki](https://github.com/jrburke/requirejs/wiki/Plugins).
  5. ## Install
  6. You can use [bower](http://bower.io/) to install it easily:
  7. ```
  8. bower install --save requirejs-plugins
  9. ```
  10. ## Plugins
  11. - **async** : Useful for JSONP and asynchronous dependencies (e.g. Google Maps).
  12. - **font** : Load web fonts using the [WebFont Loader API](https://code.google.com/apis/webfonts/docs/webfont_loader.html)
  13. (requires `propertyParser`)
  14. - **goog** : Load [Google APIs](http://code.google.com/apis/loader/)
  15. asynchronously (requires `async!` plugin and `propertyParser`).
  16. - **image** : Load image files as dependencies. Option to "cache bust".
  17. - **json** : Load JSON files and parses the result. (Requires `text!` plugin).
  18. - **mdown** : Load Markdown files and parses into HTML. (Requires `text!`
  19. plugin and a markdown converter).
  20. - **noext** : Load scripts without appending ".js" extension, useful for
  21. dynamic scripts.
  22. ### Other
  23. - **propertyParser** : Just a helper used by some plugins to parse
  24. arguments (not a real plugin).
  25. ## Documentation
  26. check the `examples` folder. All the info you probably need will be inside
  27. comments or on the example code itself.
  28. ## Basic usage
  29. Put the plugins inside the `baseUrl` folder (usually same folder as the main.js
  30. file) or create an alias to the plugin location:
  31. ```js
  32. require.config({
  33. paths : {
  34. //create alias to plugins (not needed if plugins are on the baseUrl)
  35. async: 'lib/require/async',
  36. font: 'lib/require/font',
  37. goog: 'lib/require/goog',
  38. image: 'lib/require/image',
  39. json: 'lib/require/json',
  40. noext: 'lib/require/noext',
  41. mdown: 'lib/require/mdown',
  42. propertyParser : 'lib/require/propertyParser',
  43. markdownConverter : 'lib/Markdown.Converter'
  44. }
  45. });
  46. //use plugins as if they were at baseUrl
  47. define([
  48. 'image!awsum.jpg',
  49. 'json!data/foo.json',
  50. 'noext!js/bar.php',
  51. 'mdown!data/lorem_ipsum.md',
  52. 'async!http://maps.google.com/maps/api/js?sensor=false',
  53. 'goog!visualization,1,packages:[corechart,geochart]',
  54. 'goog!search,1',
  55. 'font!google,families:[Tangerine,Cantarell]'
  56. ], function(awsum, foo, bar, loremIpsum){
  57. //all dependencies are loaded (including gmaps and other google apis)
  58. }
  59. );
  60. ```
  61. ## Removing plugin code after build
  62. [r.js](https://github.com/jrburke/r.js/blob/master/build/example.build.js)
  63. nowadays have the `stubModules` setting which can be used to remove the whole
  64. plugin code:
  65. ```js
  66. ({
  67. // will remove whole source code of "json" and "text" plugins during build
  68. // JSON/text files that are bundled during build will still work fine but
  69. // you won't be able to load JSON/text files dynamically after build
  70. stubModules : ['json', 'text']
  71. })
  72. ```
  73. ## Notes about the Markdown plugin
  74. The Markdown plugin was created mainly to be used to compile the markdown files
  75. into HTML during the build step, if you set `pragmasOnSave.excludeMdown=true`
  76. it will remove the `Markdown.Converter.js` and `mdown.js` files from the build.
  77. Example build settings:
  78. ```js
  79. ({
  80. baseUrl : './',
  81. pragmasOnSave : {
  82. excludeMdown : true
  83. },
  84. paths : {
  85. mdown : 'lib/requirejs/mdown',
  86. text : 'lib/requirejs/text',
  87. markdownConverter : 'lib/Markdown.Converter'
  88. },
  89. modules : {
  90. name : 'main'
  91. }
  92. })
  93. ```
  94. If `excludeMdown=true` you won't be able to load markdown files dynamically
  95. after the build.
  96. ## Writing your own plugins
  97. Check [RequireJS documentation](http://requirejs.org/docs/plugins.html) for
  98. a basic reference and use other plugins as reference. RequireJS official
  99. plugins are a good source for learning.
  100. Also be sure to check [RequireJS Wiki](https://github.com/jrburke/requirejs/wiki/Plugins).
  101. ## Author
  102. [Miller Medeiros](http://blog.millermedeiros.com/)
  103. ## License
  104. All the plugins are released under the MIT license.