# es6-module-transpiler

> es6-module-transpiler is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into various formats.

Latest version **0.10.0** (published 2015-01-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install es6-module-transpiler
pnpm add es6-module-transpiler
yarn add es6-module-transpiler
bun add es6-module-transpiler
```

Provides the command `compile-modules`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2015-01-22 |
| First published | 2013-02-12 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1201 |
| Author | Square, Inc. |
| Maintainers | eventualbuddha, tboyt, square |
| Keywords | es6, module, transpile, amd, commonjs |

## Links

- npm: https://www.npmjs.com/package/es6-module-transpiler
- Repository: https://github.com/square/es6-module-transpiler
- Homepage: http://esnext.github.io/es6-module-transpiler
- Issues: https://github.com/square/es6-module-transpiler/issues
- npm.io page: https://npm.io/package/es6-module-transpiler

## Dependencies (5)

- [recast](https://npm.io/package/recast.md) ^0.9.5
- [ast-util](https://npm.io/package/ast-util.md) ^0.5.1
- [reserved](https://npm.io/package/reserved.md) ^0.1.2
- [esprima-fb](https://npm.io/package/esprima-fb.md) ^7001.1.0-dev-harmony-fb
- [posix-getopt](https://npm.io/package/posix-getopt.md) ^1.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.10.0 (latest) — 2015-01-22
- 0.3.7 — 2015-01-19
- 0.9.6 — 2014-12-12
- 0.9.5 — 2014-11-15
- 0.9.4 — 2014-11-14
- 0.9.3 — 2014-11-04
- 0.9.2 — 2014-11-04
- 0.9.1 — 2014-11-04
- 0.9.0 — 2014-10-22
- 0.8.3 — 2014-10-17
- 0.8.2 — 2014-10-15
- 0.8.1 — 2014-10-15
- 0.8.0 — 2014-09-30
- 0.7.0 — 2014-09-30
- 0.6.2 — 2014-08-20
- … 16 more at https://npm.io/package/es6-module-transpiler/versions

## README

# ES6 Module Transpiler [![Build Status](https://travis-ci.org/esnext/es6-module-transpiler.png)](https://travis-ci.org/esnext/es6-module-transpiler)

ES6 Module Transpiler is an experimental compiler that allows you to write your
JavaScript using a subset of the ES6 module syntax, and compile it into
AMD or CommonJS modules.

This compiler provides a way to experiment with ES6 syntax in real world
scenarios to see how the syntax holds up. It also provides a nicer, more
declarative way to write AMD (or CommonJS) modules.

See the [CHANGELOG](./CHANGELOG.md) for the latest updates.

## Usage

### Build tools

The easiest way to use the transpiler is from an existing build tool. There
several plugins developed for different build tools:

* **Grunt:** [grunt-es6-module-transpiler](https://github.com/joefiorini/grunt-es6-module-transpiler), maintained by @joefiorini (not yet compatible with v0.5.x)
* **Gulp:** [gulp-es6-module-transpiler](https://github.com/ryanseddon/gulp-es6-module-transpiler), maintained by @ryanseddon
* **Brunch:** [es6-module-transpiler-brunch](https://github.com/gcollazo/es6-module-transpiler-brunch), maintained by @gcollazo *(CommonJS only)* (not yet compatible with v0.5.x)
* **Broccoli:** [broccoli-es6-concatenator](https://github.com/joliss/broccoli-es6-concatenator), maintained by @joliss (not yet compatible with v0.5.x)
* **Mimosa:** [mimosa-es6-module-transpiler](https://github.com/dbashford/mimosa-es6-module-transpiler), maintained by @dbashford (not yet compatible with v0.5.x)
* **AMD Formatter:** [es6-module-transpiler-amd-formatter](https://github.com/caridy/es6-module-transpiler-amd-formatter), maintained by @caridy (compatible with v0.5.x+ only)

### Executable

The transpiler can be used directly from the command line:

```
$ npm install -g es6-module-transpiler
$ compile-modules convert foo.js
```

Here is the basic usage:

```
compile-modules convert -I lib -o out FILE [FILE…]
```

### Library

You can also use the transpiler as a library:

```javascript
var transpiler = require('es6-module-transpiler');
var Container = transpiler.Container;
var FileResolver = transpiler.FileResolver;
var BundleFormatter = transpiler.formatters.bundle;

var container = new Container({
  resolvers: [new FileResolver(['lib/'])],
  formatter: new BundleFormatter()
});

container.getModule('index');
container.write('out/mylib.js');
```

## Supported ES6 Module Syntax

### Named Exports

There are two types of exports. *Named exports* like the following:

```javascript
// foobar.js
var foo = 'foo', bar = 'bar';

export { foo, bar };
```

This module has two named exports, `foo` and `bar`.

You can also write this form as:

```javascript
// foobar.js
export var foo = 'foo';
export var bar = 'bar';
```

Either way, another module can then import your exports like so:

```js
import { foo, bar } from 'foobar';

console.log(foo);  // 'foo'
```

### Default Exports

You can also export a *default* export. For example, an ES6ified jQuery might
look like this:

```javascript
// jquery.js
var jQuery = function() {};

jQuery.prototype = {
  // ...
};

export default jQuery;
```

Then, an app that uses jQuery could import it with:

```javascript
import $ from 'jquery';
```

The default export of the "jquery" module is now aliased to `$`.

A default export makes the most sense as a module's "main" export, like the
`jQuery` object in jQuery. You can use default and named exports in parallel.

### Other Syntax

#### `import "foo";`

A "bare import" that doesn't import any identifiers is useful for executing
side effects in a module. For example:

```js
// alerter.js
alert("alert! alert!");

// alertee.js
import "alerter";  // will pop up alert box
```

## Compiled Output

### Default Exports

This is super important:

**Default exports bind to an identifier on the module called `default`!**

Internally, the transpiler will use this default identifer when importing, but
any outside consumer needs to be aware that it should use the `default` key and
not the module itself. For example, a CommonJS consumer should look like this:

```js
var $ = require('jquery')['default'];
```

## Installation

Add this project to your application's package.json by running this:

    $ npm install --save es6-module-transpiler

Or install it globally:

    $ npm install -g es6-module-transpiler

## Acknowledgements

Thanks to [Yehuda Katz](https://twitter.com/wycats) for
[js_module_transpiler](https://github.com/wycats/js_module_transpiler), the
library on which this one is based. Thanks to [Dave
Herman](https://twitter.com/littlecalculist) for his work on ES6 modules.
Thanks to [Erik Bryn](https://twitter.com/ebryn) for providing the initial push
to write this library. Thanks to [Domenic
Denicola](https://twitter.com/domenic), [Jo Liss](https://twitter.com/jo_liss),
& [Thomas Boyt](https://twitter.com/thomasaboyt) for their efforts to make this
project even better. And finally thanks to the JavaScript community at Square
for helping to write and release this library.

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Any contributors to the master es6-module-transpiler repository must sign the
[Individual Contributor License Agreement (CLA)][cla].  It's a short form that
covers our bases and makes sure you're eligible to contribute.

[cla]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1

When you have a change you'd like to see in the master repository, [send a pull
request](https://github.com/esnext/es6-module-transpiler/pulls). Before we merge
your request, we'll make sure you're in the list of people who have signed a
CLA.

Thanks, and enjoy living in the ES6 future!

---
_Source: https://npm.io/package/es6-module-transpiler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
