Skip to content

Commit 0422d5f

Browse files
committed
Enable the UMD behavior for bundlers compatibility
1 parent fed84cc commit 0422d5f

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,34 @@ npm install --save gridstack
7171

7272
## Include
7373

74-
after you install:
74+
* Using webpack, you can now import the files:
7575

7676
```js
77-
import 'gridstack/dist/gridstack.all.js';
77+
import 'jquery';
78+
import 'jquery-ui';
79+
80+
import 'gridstack/dist/gridstack-poly'; // optional IE support
81+
import GridStack from 'gridstack/dist/gridstack';
82+
import 'gridstack/dist/gridstack.jQueryUI';
7883
import 'gridstack/dist/gridstack.css';
7984
```
85+
86+
If your project doesn't make use of jQuery or jQueryUI and you don't want to include these libs,
87+
you can use the lightweight files provided by Gridstack instead of the official ones.
88+
89+
For this you have to define an alias in your webpack configuration:
90+
```
91+
module.exports = {
92+
...
93+
resolve: {
94+
alias: {
95+
'jquery': 'gridstack/dist/jquery.js',
96+
'jquery-ui': 'gridstack/dist/jquery-ui.js',
97+
}
98+
}
99+
}
100+
```
101+
80102
* alternatively in html
81103

82104
```html

src/gridstack.jQueryUI.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
* gridstack.js may be freely distributed under the MIT license.
66
*/
77
(function(factory) {
8-
/* we compile this in so no need for required loading
98
if (typeof define === 'function' && define.amd) {
109
define(['jquery', 'gridstack', 'exports'], factory);
1110
} else if (typeof exports !== 'undefined') {
1211
try { jQuery = require('jquery'); } catch (e) {}
1312
try { gridstack = require('gridstack'); } catch (e) {}
1413
factory(jQuery, gridstack.GridStack, exports);
15-
} else */{
14+
} else {
1615
factory(jQuery, GridStack, window);
1716
}
1817
})(function($, GridStack, scope) {

src/gridstack.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* @preserve
77
*/
88
(function(factory) {
9-
/* [alain] we compile jquery with our code, so no need to 'load' externally
109
if (typeof define === 'function' && define.amd) {
1110
define(['jquery', 'exports'], factory);
1211
} else if (typeof exports !== 'undefined') {
@@ -15,7 +14,7 @@
1514
try { jQueryModule = require('jquery'); } catch (e) {}
1615

1716
factory(jQueryModule || window.jQuery, exports);
18-
} else */{
17+
} else {
1918
factory(window.jQuery, window);
2019
}
2120
})(function($, scope) {

src/jquery-ui.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* Copyright jQuery Foundation and other contributors; Licensed MIT @preserve*/
55

66
(function( factory ) {
7-
/* [alain] we compile this in so no need to load with AMD
87
if ( typeof define === "function" && define.amd ) {
98

109
// AMD. Register as an anonymous module.
1110
define([ "jquery" ], factory );
12-
} else */{
11+
} else {
1312

1413
// Browser globals
1514
factory( jQuery );

0 commit comments

Comments
 (0)