ES6ModuleTranspiler-Rails
Transpile ES6 Modules in the Rails Asset Pipeline
Uses Square's ES6 Module Transpiler
Installation
Node.js must be installed for the transpiling to happen
gem 'es6_module_transpiler-rails'
Usage
Your modules will transpile and are named based upon their directory
nesting + filename, as long as the file has the .es6
extension.
For example, app/assets/javascripts/controllers/fooController.js.es6
var fooController = function() {
console.log('fooController is in the house!')
};
export default = fooController;
will compile to /assets/controllers/fooController.js
define("controllers/fooController",
["exports"],
function(__exports__) {
"use strict";
var fooController = function() {
console.log('fooController is in the house!')
};
__exports__["default"] = fooController;
});
Compiling
By default your module will compile to an AMD. You can also compile it to globals or CommonJS by making the following switch:
ES6ModuleTranspiler.compile_to = :globals
# or
ES6ModuleTranspiler.compile_to = :cjs
Custom Module Prefix
You can match module names based upon a pattern to apply a prefix to the name:
ES6ModuleTranspiler.prefix_pattern = [/^(controllers|models|views|helpers|routes|router|store)/, 'app']
This would match names that start with the pattern and prepend with
app/
. For example, controllers/fooController
would now be named
app/controllers/fooController
.
Note the path is the logical path for the asset. For example, if the
path to your asset is
app/assets/javascripts/controllers/fooController.js.es6
the logical
path is controllers/fooController
.
Authors
We are very thankful for the many contributors
Versioning
This gem follows Semantic Versioning
Want to help?
Please do! We are always looking to improve this gem.
Legal
DockYard, LLC © 2013