# es6-module-clean-transpilation

> es6-module-clean-transpilation is an experimental compiler that allows you to write your JavaScript using a subset of the current ES6 module syntax, and compile it into clean AMD, CommonJS, UMD and globals styles.

Latest version **0.3.3** (published 2015-07-10) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install es6-module-clean-transpilation
pnpm add es6-module-clean-transpilation
yarn add es6-module-clean-transpilation
bun add es6-module-clean-transpilation
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2015-07-10 |
| First published | 2015-07-04 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | munawwar |
| Keywords | es6, module, transpile, amd, commonjs |

## Links

- npm: https://www.npmjs.com/package/es6-module-clean-transpilation
- Repository: https://github.com/Munawwar/es6-module-clean-transpilation
- Homepage: https://github.com/Munawwar/es6-module-to-es5
- Issues: https://github.com/Munawwar/es6-module-clean-transpilation/issues
- npm.io page: https://npm.io/package/es6-module-clean-transpilation

## Dependencies (2)

- [nomnom](https://npm.io/package/nomnom.md) 1.8.1
- [shelljs](https://npm.io/package/shelljs.md) 0.5.1

## 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.3.3 (latest) — 2015-07-10
- 0.3.2 — 2015-07-08
- 0.3.1 — 2015-07-08
- 0.3.0 — 2015-07-08
- 0.2.2 — 2015-07-08
- 0.2.1 — 2015-07-07
- 0.2.0 — 2015-07-07
- 0.1.1 — 2015-07-04

## README

# ES6 Module Clean Transpilation

## WHY?

Philosophy is to "write once and compile *cleanly* to any dependency management".

The idea is to be **able** to compile to all dependency management (AMD, CJS, globals) even
if you don't intend to publish your library/code with support for all of them.

Secondly the generated code should be usable by existing AMD and globals using code bases.

And hence this comes with some trade-offs and code conventions. Only a subset of the current ES6 module syntax can be supported.
Specifically only default imports and default exports can be supported. Named imports, named imports and bare imports are excluded (more info on that later in this page).

**Hence it is mandatory to follow the convention: All JS files should export a default object and when importing, only use default imports**.

## Usage

The transpiler can be used directly from the command line:

```
node transpiler.js -t amd -i src/ -o dist/
```

Here is the basic usage:

```bash
Usage: node transpiler.js [options]

Options:
   -i, --input    path to file
   -o, --output   path to output file or directory  [stdout]
   -t, --type     Type of output required - amd, cjs, umd or globals  [amd]
```

### Library

You can also use the transpiler as a library:

```javascript
var compiler = require("es6-module-clean-transpilation");

var output = compiler({
  type: 'amd',
  input: 'path/to/input',
  output: 'path/to/output'
});
```

## Supported ES6 Module Syntax

### Default Exports and Imports

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

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

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

export default = jQuery;
```

It is mandatory that **all** javascript files have a default export (only then, AMD can be perfectly supported).

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.

### Unsupported Syntax

### Bare imports

Bare imports like:
```
import "jquery"
```
isn't AMD and CJS friendly (but only globals friendly). Hence, it isn't supported (going with "the common denominator").
One should write code in such a way that all dependency management is supported.

### Named Exports

Won't support named exports nor multiple export statements, as they cannot be compiled to nice AMD code.

If we had to support both default and named exports then *the consumer of a module would have to add boilerplate code* like this:

```js
define(["jquery"],
  function(jQuery) {
    var $ = jQuery['default'];
    ...
  });
```
And *that* isn't convenient for users of your code (especially when trying to use a compiled reusable library in an non-compiled app).

#### `module`

Currently we don't support this as this fork already doesn't support multiple exports. So this syntax is redundant.

The following..:
```js
module foobar from "foobar";
console.log(foobar.foo);  // "foo"
```

..can be replaced with:
```js
import foo from "foobar";
console.log(foo);  // "foo"
```

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