Skip to content

Commit 992cc0d

Browse files
committed
put the AMD definitions before the commonjs - some build tools expose am exports object
1 parent d20873c commit 992cc0d

5 files changed

Lines changed: 26 additions & 26 deletions

File tree

commonjsStrict.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
// the top function.
1818

1919
(function (root, factory) {
20-
if (typeof exports === 'object') {
21-
// CommonJS
22-
factory(exports, require('b'));
23-
} else if (typeof define === 'function' && define.amd) {
20+
if (typeof define === 'function' && define.amd) {
2421
// AMD. Register as an anonymous module.
2522
define(['exports', 'b'], factory);
23+
} else if (typeof exports === 'object') {
24+
// CommonJS
25+
factory(exports, require('b'));
2626
} else {
2727
// Browser globals
2828
factory((root.commonJsStrict = {}), root.b);

commonjsStrictGlobal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
// in the browser, it will create a global .b that is used below.
1818

1919
(function (root, factory) {
20-
if (typeof exports === 'object') {
21-
// CommonJS
22-
factory(exports, require('b'));
23-
} else if (typeof define === 'function' && define.amd) {
20+
if (typeof define === 'function' && define.amd) {
2421
// AMD. Register as an anonymous module.
2522
define(['exports', 'b'], function (exports, b) {
2623
factory((root.commonJsStrictGlobal = exports), b);
2724
});
25+
} else if (typeof exports === 'object') {
26+
// CommonJS
27+
factory(exports, require('b'));
2828
} else {
2929
// Browser globals
3030
factory((root.commonJsStrictGlobal = {}), root.b);

jqueryPluginCommonjs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// not want to add the extra CommonJS detection.
88

99
(function (factory) {
10-
if (typeof exports === 'object') {
11-
// Node/CommonJS
12-
factory(require('jquery'));
13-
} else if (typeof define === 'function' && define.amd) {
10+
if (typeof define === 'function' && define.amd) {
1411
// AMD. Register as an anonymous module.
1512
define(['jquery'], factory);
13+
} else if (typeof exports === 'object') {
14+
// Node/CommonJS
15+
factory(require('jquery'));
1616
} else {
1717
// Browser globals
1818
factory(jQuery);

returnExports.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
// the top function.
1616

1717
(function (root, factory) {
18-
if (typeof exports === 'object') {
18+
if (typeof define === 'function' && define.amd) {
19+
// AMD. Register as an anonymous module.
20+
define(['b'], factory);
21+
} else if (typeof exports === 'object') {
1922
// Node. Does not work with strict CommonJS, but
2023
// only CommonJS-like enviroments that support module.exports,
2124
// like Node.
2225
module.exports = factory(require('b'));
23-
} else if (typeof define === 'function' && define.amd) {
24-
// AMD. Register as an anonymous module.
25-
define(['b'], factory);
2626
} else {
2727
// Browser globals (root is window)
2828
root.returnExports = factory(root.b);
@@ -39,14 +39,14 @@
3939

4040
// if the module has no dependencies, the above pattern can be simplified to
4141
(function (root, factory) {
42-
if (typeof exports === 'object') {
42+
if (typeof define === 'function' && define.amd) {
43+
// AMD. Register as an anonymous module.
44+
define(factory);
45+
} else if (typeof exports === 'object') {
4346
// Node. Does not work with strict CommonJS, but
4447
// only CommonJS-like enviroments that support module.exports,
4548
// like Node.
4649
module.exports = factory();
47-
} else if (typeof define === 'function' && define.amd) {
48-
// AMD. Register as an anonymous module.
49-
define(factory);
5050
} else {
5151
// Browser globals (root is window)
5252
root.returnExports = factory();

returnExportsGlobal.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
// in the browser, it will create a global .b that is used below.
1616

1717
(function (root, factory) {
18-
if (typeof exports === 'object') {
19-
// Node. Does not work with strict CommonJS, but
20-
// only CommonJS-like enviroments that support module.exports,
21-
// like Node.
22-
module.exports = factory(require('b'));
23-
} else if (typeof define === 'function' && define.amd) {
18+
if (typeof define === 'function' && define.amd) {
2419
// AMD. Register as an anonymous module.
2520
define(['b'], function (b) {
2621
return (root.returnExportsGlobal = factory(b));
2722
});
23+
} else if (typeof exports === 'object') {
24+
// Node. Does not work with strict CommonJS, but
25+
// only CommonJS-like enviroments that support module.exports,
26+
// like Node.
27+
module.exports = factory(require('b'));
2828
} else {
2929
// Browser globals
3030
root.returnExportsGlobal = factory(root.b);

0 commit comments

Comments
 (0)