Skip to content

Commit 2a9dbdf

Browse files
Fix ES6 support using Babel::Transpiler
Tested on sprockets 3.7.1 with sprockets-es6 0.9.2, but should also work on sprockets 4.x with babel-transpiler gem. This also allows to use ES6 `export default` for defining components.
1 parent e86e33a commit 2a9dbdf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/sprockets/vue/script.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ class << self
1212
CoffeeScript.compile(s, sourceMap: true, sourceFiles: [input[:source_path]], no_wrap: true)
1313
},
1414
'es6' => ->(s, input){
15-
Babel::Transpiler.transform(data, {}) #TODO
15+
opts = {
16+
'sourceRoot' => input[:load_path],
17+
'moduleRoot' => nil,
18+
'filename' => input[:filename],
19+
'filenameRelative' => input[:environment].split_subpath(input[:load_path], input[:filename])
20+
}
21+
22+
result = Babel::Transpiler.transform(s, opts)
23+
24+
{ 'js' => result['code'] }
1625
},
1726
nil => ->(s,input){ { 'js' => s } }
1827
}
@@ -30,7 +39,7 @@ def call(input)
3039
map = result['sourceMap']
3140

3241
output << "'object' != typeof VComponents && (this.VComponents = {});
33-
var module = { exports: null };
42+
var module = { exports: null }, exports = {};
3443
#{result['js']}; VComponents['#{name}'] = module.exports;"
3544
end
3645

0 commit comments

Comments
 (0)