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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f82f79b5fd9ff5d46f376d2abb21618bfaf153c
4
- data.tar.gz: b85f2fa1b065f28036f6febdf97a10cc6b3fb5e6
3
+ metadata.gz: 3f2a259c66a7efbeed23a5492fa265f6a42dd9ff
4
+ data.tar.gz: 7a117702038a8ed033413731155f03f547ac8cea
5
5
  SHA512:
6
- metadata.gz: da30c5e0f2b63c1119cddac625e53c53960e97606a571a8a7715e03ecea8cdfdbc63d5325271ffc790bb4100f0c07a8c36e2147e21e6fc76bbac94c96ab76a8c
7
- data.tar.gz: 436792b1994522f6e0595988c0a4088a9a3fc37a053a3bc8eafd2e148235d1797bbf787e17f332c3e5fe39cc9c753baf7dad314d9cb74883f7fccdae8ada5ebd
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
- Default module defie logic is to use "inline". However, that generates extra boilerplate on every file,
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
 
@@ -209,5 +209,5 @@ module Sprockets
209
209
  end
210
210
  end
211
211
 
212
- register_engine '.es6', Babel::Template
212
+ register_engine '.es6', Babel::Template, mime_type: 'application/javascript', silence_deprecation: true
213
213
  end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Babel
3
- VERSION = '0.0.10'
3
+ VERSION = '0.0.11'
4
4
  end
5
5
  end
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.10
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-07-09 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets