sprockets-babel-miniracer 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +116 -1
- data/lib/sprockets/babel.rb +1 -1
- data/lib/sprockets/babel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f2a259c66a7efbeed23a5492fa265f6a42dd9ff
|
4
|
+
data.tar.gz: 7a117702038a8ed033413731155f03f547ac8cea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 224789322dd28b3572ab08557ad980da2caa0bbee6227880ba7610f201f7ee5c42c87f144c81a660f53ea22922a699f14e4655b67ea1a77664c6f3d93c0505a7
|
7
|
+
data.tar.gz: 1fb93dbc9bdab5e9f33887949e35c2dbee0ab01d8e1e57126de4b27c9dfdf21b32af18e4f1a5d2092b36ada39feba093d5d24dbbfbee16e37854c851a380e47e
|
data/README.md
CHANGED
@@ -8,9 +8,12 @@ This is intended as a temporary solution until Sprockets 2.x can be upgraded.
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
### Inline
|
12
|
+
Default module define logic is to use "inline". However, that generates extra boilerplate on every file,
|
12
13
|
which accumulates to be plenty with lot fo files.
|
13
14
|
|
15
|
+
### AMD
|
16
|
+
|
14
17
|
Using 'amd' allows to reduce boilerplate, but requires including "define.js" before es6 files in manifest.
|
15
18
|
|
16
19
|
config/initializers/babel.rb
|
@@ -25,6 +28,118 @@ app/assets/javascripts/application.js
|
|
25
28
|
//= require sprockets-babel-miniracer/define
|
26
29
|
```
|
27
30
|
|
31
|
+
### SystemJS
|
32
|
+
|
33
|
+
Recommended appraoch is to use systemjs instead of AMD. This provides more comprehensive logic for
|
34
|
+
setting up environment.
|
35
|
+
|
36
|
+
config/initializers/babel.rb
|
37
|
+
```
|
38
|
+
Babel.options do |opt|
|
39
|
+
opt[:modules] = 'system'
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
app/assets/javascripts/application.js
|
44
|
+
```
|
45
|
+
// NOTE KI assuming that systemjs is included somehow into vendor assets
|
46
|
+
//= require system.js-0.19.31/system-polyfills.src
|
47
|
+
//= require system.js-0.19.31/system.src
|
48
|
+
```
|
49
|
+
|
50
|
+
For initialization purposes following utility may be helpfull
|
51
|
+
|
52
|
+
app/assets/javascripts/shared/gi.js
|
53
|
+
```javascript
|
54
|
+
(function() {
|
55
|
+
'use strict';
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @return promise to get module
|
59
|
+
*/
|
60
|
+
function importModule(name) {
|
61
|
+
return System
|
62
|
+
.import(name)
|
63
|
+
.catch(function(err) {
|
64
|
+
console.error("module not found: " + name);
|
65
|
+
|
66
|
+
console.log(err);
|
67
|
+
console.log(err.message);
|
68
|
+
console.log(err.stack);
|
69
|
+
|
70
|
+
var err2 = err.originalErr;
|
71
|
+
if (err2) {
|
72
|
+
console.log(err2);
|
73
|
+
console.log(err2.message);
|
74
|
+
console.log(err2.stack);
|
75
|
+
}
|
76
|
+
|
77
|
+
throw err;
|
78
|
+
});
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Asynchronouslyl load and init ES6 module via document ready hook
|
83
|
+
*
|
84
|
+
* @return module load promise
|
85
|
+
*/
|
86
|
+
function initModule(name) {
|
87
|
+
return importModule(name).then(function(module) {
|
88
|
+
if (module.init) {
|
89
|
+
console.debug('INIT: '+ name);
|
90
|
+
try {
|
91
|
+
module.init();
|
92
|
+
} catch (e) {
|
93
|
+
console.error("INIT FAILED: " + name);
|
94
|
+
console.error(e);
|
95
|
+
console.error(e.message);
|
96
|
+
console.error(e.stack);
|
97
|
+
|
98
|
+
var e2 = e.originalException;
|
99
|
+
if (e2) {
|
100
|
+
console.error(e2);
|
101
|
+
console.error(e2.message);
|
102
|
+
console.error(e2.stack);
|
103
|
+
}
|
104
|
+
|
105
|
+
throw e;
|
106
|
+
};
|
107
|
+
} else {
|
108
|
+
console.warn('NO INIT: ' + name);
|
109
|
+
}
|
110
|
+
});
|
111
|
+
// .catch(function(err) {
|
112
|
+
// console.warn('INIT failed: ' + err.message);
|
113
|
+
// });
|
114
|
+
}
|
115
|
+
|
116
|
+
window.gi = window.gi || {};
|
117
|
+
|
118
|
+
_.assign(window.gi, {
|
119
|
+
importModule: importModule,
|
120
|
+
initModule: initModule,
|
121
|
+
});
|
122
|
+
})();
|
123
|
+
```
|
124
|
+
|
125
|
+
app/assets/javascripts/test/module.js
|
126
|
+
```javascript
|
127
|
+
$(function() {
|
128
|
+
gi.initModule('test/test').then(function() {
|
129
|
+
...
|
130
|
+
});
|
131
|
+
});
|
132
|
+
```
|
133
|
+
|
134
|
+
app/assets/javascripts/test/module.js
|
135
|
+
```javascript
|
136
|
+
export function init() {
|
137
|
+
...
|
138
|
+
}
|
139
|
+
```
|
140
|
+
|
141
|
+
*References*
|
142
|
+
[SystemJS](https://github.com/systemjs/systemjs)
|
28
143
|
|
29
144
|
## Background
|
30
145
|
|
data/lib/sprockets/babel.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-babel-miniracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kari Ikonen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|