-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathUMD.javascript.txt
60 lines (54 loc) · 3.99 KB
/
UMD.javascript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
┏━━━━━━━━━┓
┃ UMD ┃
┗━━━━━━━━━┛
MODULE LOADING ==> #Goals:
# - executing JavaScript dynamically (files are still read/fetched)
# - organizing code in several files
# - handling dependencies
TYPES ==> # - Global variables:
# - GLOBAL.VAR = VAL
# - sync
# - no namespacing, no dynamic loading, no dependencies handling
# - AMD:
# - define(), like requireJS
# - Angular|Backbone have AMD-syntax, but not same advantages
# - async
# - can load non-JavaScript
# - can run natively client-side
# - can have several exports per file
# - CommonJS-like:
# - require() and exports, like Node.js and browserify
# - sync
# - less verbose
# - usually server-side
# - ES6:
# - export VAL and import VAR from MODULE
# - less verbose
# - sync
# - will run natively client-side when browsers suppport it
# - can have several exports per file
UMD ==> #Universal Module Definition: wrapper that fits AMD, Node.js/browserify
#(not CommonJS), Global
(function( root, factory ){
if ( typeof define === 'function' && define.amd ) {
define( [ ['DEP'] ], factory );
} else if ( typeof exports === 'object' ) {
module.exports = factory([require('DEP')]);
} else {
root.VAR = factory([root.DEP]);
}
}(this, function([DEP]) {
// Here goes the library$
return OBJ|FUNC;
}));
GULP-WRAP-UMD(OBJ) #Gulp plugin (0.2.1)
#Wrap IOSTREAM with UMD. OBJ members are:
# - deps OBJ|STR_ARR: DEP_ARR to use.
# OBJ allow different names:
# - name STR: in everything else
# - cjsName: in require()
# - amdName: in define()
# - globalName: in root.*
# - paramName: in function()
# - exports STR: return ...; (déf: last file line)
# - namespace STR: root.... = factory() (déf: "gulpWrapUmd")