A List of actively-supported, reusable, open-source, AMD-compliant modules in the wild. Let me know if you have another module to add to the list!
There are a couple of things that bug me about RequireJS's data-main method of single-script loading:
<script src="js/requirejs/require.js" data-main="app/main.js"></script>
- the built file (bundle) must be named "require.js". WAT.
- it just seems backwards.
data-main
does not follow w3c recommendations since it's not name-spaced.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (define, frakkedConstructor) { define(function (require) { "use strict"; | |
var removeCommentsRx, findFuncRx, fracPrefixSrc, fracSuffixSrc, | |
undef; | |
removeCommentsRx = /\/\*[\s\S]*?\*\/|(?:[^\\])\/\/.*?[\n\r]/g; | |
findFuncRx = /(function\s+NAME\s*\([^\{]+\{)|(?:[^\\]?)(["'])|(\{)|(\})/g; | |
// TODO: allow individual parameters to be modified | |
// TODO: allow function return to be modified or passed to after() | |
fracPrefixSrc = 'frak$backs.before.apply(this, arguments); try {'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is a simple module with no id. The loader will assign an id | |
* according to the url where this file was found. This is done with | |
* a mapping of id:url, typically, but could be done via url:id as is | |
* proposed by some ES6 discussions. | |
*/ | |
define(function (require) { | |
var wire, spec; | |
wire = require('wire'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Typical AMD factory that returns a value, but uses an r-value (sync) require(), | |
// rather than a long, awkward dependency list. | |
// You cannot use module.exports or exports to declare the module: | |
(function (define){ | |
define(function (require) { | |
"use strict"; | |
var mod = require('pkb/modA'); | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function (require, exports) { | |
var foo = require('foo'); | |
exports.bar = 'bar'; | |
}); | |
// this also works: | |
define(function (require) { | |
var foo = require('foo'); | |
return { bar: 'bar' }; | |
}); |
- Bytes and Blobs by David Flanagan
- Conference Wifi Redux by Malte Ubi
- Sashimi - https://github.com/cramforce/Sashimi
- Run Your JS everywhere with Jellyfish by Adam Christian - http://jelly.io Project
- Fighting Crime and Kicking Apps with Batman.js by Nick Small
- Hello Jo by Dave Balmer - Project - http://joapp.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone github:lenary/guides.git | |
Cloning into guides... | |
remote: Counting objects: 255, done. | |
remote: Compressing objects: 100% (216/216), done. | |
remote: Total 255 (delta 111), reused 163 (delta 35) | |
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done. | |
Resolving deltas: 100% (111/111), done. | |
$ cd guides | |
$ git remote -v |
Used: q-spec.js@a1a416.
Implementations compared:
This is currently in Q:
The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:
- How can authors of function-modules convert to ES6
export
syntax, without breaking consumers that dorequire("function-module")()
? - How can consumers of function-modules use ES6
import
syntax, while not demanding that the module author rewrites his code to ES6export
?
@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.
This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.
NewerOlder