Home

Awesome

mimosa-es6-module-transpiler

Overview

This module will allow you to utilize ES6 module syntax when building your client code. It will transpile your JavaScript with ES6 syntax to AMD or CommonJS compliant JavaScript. It can also output code that attaches modules to global scope.

For more information regarding Mimosa, see http://mimosa.io

Usage

Add 'es6-module-transpiler' to your list of modules. That's all! Mimosa will install the module for you when you start up.

Functionality

This module will take your ES6 module syntax code and compile it down to a syntax usable with common module specs: AMD and CommonJS.

It will also allow you to compile it down to a format that exports code globally. If a module is exported globally, you may want to declare any imports it might have. See the Example Config below.

Using a JavaScript transpiler like CoffeeScript? For syntax like import to survive being transpiled, you must use the compilers built-in ability to pass some code through the transpiler. CoffeeScript, for instance, uses the backtick to essentially have the CoffeeScript compiler ignore the code contained within.

The CoffeeScript code below in an example:

`import $ from "jquery"`
`import templates from "templates"`

class ExampleView

...

`export default ExampleView`

will be compiled to

define(
  ["jquery","templates"],
  function($, templates) {
    "use strict";
    var ExampleView;

    ...

    return ExampleView;
  });

Note: The ES6 transpiler currently does not support source maps. So source maps will not be generated, nor will source maps already present (as from CoffeeScript) be honored or updated. They will not, however, be removed.

Note: The ES6 module syntax is fluid and may change down the road.

Note: This does not support the full set of ES6 module syntax, but it does the support the major pieces. This module wraps square's transpiler, so as it adds features and more feature support this module will benefit.

Default Config

es6Modules: {
  type:"amd",
  inferName:true,
  exclude: [/[/\\]vendor[/\\]/, /[/\\]main[\.-]/, /-main.js$/, /[/\\]common.js$/],
  globals:{}
}

Example Config

es6Modules:
  type:"globals"
  globals:
    "/javascripts/app/example":
      global: "ExampleApp"
      imports:
        jquery: "$"