RubyEs6ModuleTranspiler
ES6 Module Transpiler Ruby Gem, a handy little gem to help convert your ES6 code into CommonJS, AMD or YUI formats using Square's ES6 Module Transpiler.
Installation
Add this line to your application's Gemfile:
gem 'ruby_es6_module_transpiler'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ruby_es6_module_transpiler
Usage
Note that Node.js is required for the transpiling.
Add the necessary require to the file in which the gem is needed
require 'ruby_es6_module_transpiler'
Call transpile with ES6 code. By default, it will transpile to AMD. For example, calling
js_code = <<-JS
import { get, set } from 'ember';
JS
RubyES6ModuleTranspiler.transpile(js_code)
will return
define(
["ember"],
function(__dependency1__) {
"use strict";
var get = __dependency1__.get;
var set = __dependency1__.set;
});
You can also add in extra options like so:
js_code = <<-JS
import { get, set } from 'ember';
JS
RubyES6ModuleTranspiler.transpile(js_code, { type: "Globals", global: "renamed"})
which returns
(function(__dependency1__) {
"use strict";
var get = __dependency1__.get;
var set = __dependency1__.set;
})(renamed.ember);
Check out Square's ES6 Module Transpiler for more info on the various options available.
Contributing
Feedback and PRs always welcome!
To submit a PR:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Legal
Licensed under the MIT license
Extra
Please also check out the the Rails gem and a rake pipeline filter that uses this gem!