ruby-babel-transpiler
ruby-babel-transpiler copied to clipboard
how to use babel transpiler in ruby
Hi,
I am novice to ruby also es6
have created file foo.es6 which contains below code
class View {
constructor(options) {
this.model = options.model;
this.template = options.template;
}
render() {
return _.template(this.template, this.model.toObject());
}
}
in ubuntu command line sudo gem install babel-transpiler -which installed babel-gem
then running ruby file esjs.rb
require 'babel/transpiler'
Babel::Transpiler.transform File.read("foo.es6")
will this convert es6 to js??
@bharathsn0812 You can see the usage here - https://github.com/babel/ruby-babel-transpiler/blob/master/test/test_babel_transpiler.rb
@bharathsn0812 Just to add to this, here's an example of what I'm doing https://github.com/jwoertink/fez/blob/master/src/templates/Rakefile.ecr#L5-L10
The Babel::Transpiler.transform
method will return a hash where the code
key is a giant string of the converted code. Just write that to a file, and call it "whatever.js".