sprockets-babel-miniracer 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/{lib/sprockets-babel-inline-module-loader.js → app/assets/javascripts/sprockets-babel-miniracer/define.js} +4 -3
- data/lib/babel.rb +7 -1
- data/lib/sprockets/babel.rb +3 -3
- data/lib/sprockets/babel/railtie.rb +39 -0
- data/lib/sprockets/babel/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b9e786bd2a5be9671ffd010be79846e9489f836
|
4
|
+
data.tar.gz: ddceedac186a787b8d284e3773a077f4737a08d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 468a28fb603e50266bb785d5f2f9d5aecbea4ad300c06c7aed63b8cdf60fefb00f305d3ffb2814a81981aa21f3c6c89c2ad9ad46bf5e0e50c45cf75e6be2d40b
|
7
|
+
data.tar.gz: 2a90fd0348433a6dfadaf2e6c4b627933dc5d69be1143908adec8f3a9f2ccf5238c16ea0e210e1ba0c7f734fe10300b5f965cfdb21a1dcc1d5d84f85f5e4c9ac
|
data/README.md
CHANGED
@@ -6,8 +6,34 @@ the ES6 transpiler in a Sprockets 2.x environment.
|
|
6
6
|
|
7
7
|
This is intended as a temporary solution until Sprockets 2.x can be upgraded.
|
8
8
|
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Default module defie logic is to use "inline". However, that generates extra boilerplate on every file,
|
12
|
+
which accumulates to be plenty with lot fo files.
|
13
|
+
|
14
|
+
Using 'amd' allows to reduce boilerplate, but requires including "define.js" before es6 files in manifest.
|
15
|
+
|
16
|
+
config/initializers/babel.rb
|
17
|
+
```
|
18
|
+
Babel.options do |opt|
|
19
|
+
opt[:modules] = 'amd'
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
app/assets/javascripts/application.js
|
24
|
+
```
|
25
|
+
//= require sprockets-babel-miniracer/define
|
26
|
+
```
|
27
|
+
|
28
|
+
|
9
29
|
## Background
|
10
30
|
|
31
|
+
NOTE KI
|
32
|
+
|
33
|
+
Created to allow support for miniracer, and to fix some minor logic bugs
|
34
|
+
|
35
|
+
Original: [sprockets-babel](70mainstreet/sprockets-babel)
|
36
|
+
|
11
37
|
I created this gem for the following reasons:
|
12
38
|
|
13
39
|
* I need Babel for IE 8 support, but
|
@@ -1,6 +1,6 @@
|
|
1
1
|
(function(global) {
|
2
2
|
global.define = function(moduleId, importIds, body) {
|
3
|
-
|
3
|
+
function resolveRelativeModuleId(targetId) {
|
4
4
|
var targetParts = targetId.split(/\//),
|
5
5
|
basename = targetParts.pop();
|
6
6
|
if ((targetParts.length == 0) || (targetParts[0] != '.' && targetParts[0] != '..')) {
|
@@ -21,8 +21,9 @@
|
|
21
21
|
var parts = fromParts.concat(targetParts);
|
22
22
|
return (parts.length == 0) ? basename : parts.join('/') + '/' + basename;
|
23
23
|
};
|
24
|
-
|
25
|
-
|
24
|
+
|
25
|
+
function toVariableName(moduleId) {
|
26
|
+
return '$__' + encodeURIComponent(moduleId.replace(/^\.\//, ''))
|
26
27
|
.replace(/%|-/g, '') + '__';
|
27
28
|
};
|
28
29
|
|
data/lib/babel.rb
CHANGED
data/lib/sprockets/babel.rb
CHANGED
@@ -136,8 +136,8 @@ module Sprockets
|
|
136
136
|
var exports = {};
|
137
137
|
global.#{module_var} = exports;
|
138
138
|
|
139
|
-
|
140
|
-
|
139
|
+
function define(moduleId, importIds, body) {
|
140
|
+
function resolveRelativeModuleId(targetId) {
|
141
141
|
var targetParts = targetId.split(/\\//),
|
142
142
|
basename = targetParts.pop();
|
143
143
|
if ((targetParts.length == 0) || (targetParts[0] != '.' && targetParts[0] != '..')) {
|
@@ -169,7 +169,7 @@ module Sprockets
|
|
169
169
|
}
|
170
170
|
|
171
171
|
var importId = resolveRelativeModuleId(importIds[i]),
|
172
|
-
variable = '$__' + encodeURIComponent(importId.replace(
|
172
|
+
variable = '$__' + encodeURIComponent(importId.replace(/^\\.\\//, ''))
|
173
173
|
.replace(/%|-/g, '') + '__';
|
174
174
|
imports.push(global[variable]);
|
175
175
|
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "sprockets/railtie"
|
2
|
+
|
3
|
+
module Sprockets
|
4
|
+
module Babel
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
# assets
|
7
|
+
initializer 'base' do |app|
|
8
|
+
register_asset_paths(app)
|
9
|
+
end
|
10
|
+
|
11
|
+
rake_tasks do
|
12
|
+
Base.load_tasks
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def register_asset_paths(app)
|
18
|
+
base_dirs = [
|
19
|
+
'app',
|
20
|
+
]
|
21
|
+
|
22
|
+
asset_dirs = [
|
23
|
+
'javascripts',
|
24
|
+
]
|
25
|
+
|
26
|
+
assets = app.config.assets
|
27
|
+
base_dirs.each do |base_dir|
|
28
|
+
asset_dirs.each do |asset_dir|
|
29
|
+
path = "#{::Babel.gem_root_dir}/#{base_dir}/assets/#{asset_dir}"
|
30
|
+
if File.exist?(path)
|
31
|
+
::Rails.logger.info "asset_path: #{path}"
|
32
|
+
config.assets.paths << path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.
|
4
|
+
version: 0.0.9
|
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-
|
11
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -78,10 +78,11 @@ files:
|
|
78
78
|
- LICENSE.txt
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
|
+
- app/assets/javascripts/sprockets-babel-miniracer/define.js
|
81
82
|
- lib/babel.rb
|
82
|
-
- lib/sprockets-babel-inline-module-loader.js
|
83
83
|
- lib/sprockets-babel-miniracer.rb
|
84
84
|
- lib/sprockets/babel.rb
|
85
|
+
- lib/sprockets/babel/railtie.rb
|
85
86
|
- lib/sprockets/babel/version.rb
|
86
87
|
- sprockets-babel-miniracer.gemspec
|
87
88
|
- test/fixtures/Regions.js.es6
|