schteppe/p2.js — pull request #121 by timrwood (2014-07-24 17:22:54+00:00)
Title: ES6 Modules

This is a first pass at converting the source to [ES6 modules](http://jsmodules.io/).

It's still WIP, so tests don't pass yet. I just wanted to see if this was something you were interested in.

One of the benefits of ES6 modules is that you would be able to do something like this.

```js
import { Body, World, Circle } from "p2";

var world = new World({ gravity : [0,-10] });
var body = new Body();
body.addShape(new Circle(10));
world.addBody(body);
```

You can transpile ES6 modules to ES5 using something like [square/es6-module-transpiler](https://github.com/square/es6-module-transpiler).

```sh
npm install -g es6-module-transpiler
compile-modules convert -I src -o build/p2.es6.js src/p2.js
```

An example of how the output might look is here. https://gist.github.com/timrwood/5f96de256ec9768f70b5

Using the bundle format from the es6-module-transpiler also has some significant file savings over browserify.

After some rough tests, it was around half the un-gzipped size of the browserify build and 66% of the gzipped size. I didn't think it was worth comparing exact file sizes until tests are passing and poly-decomp is included.

Sorry for the brain dump, just wanted to get out all the talking points.

TODO:
- [ ] Figure out a solution for importing poly-decomp
- [ ] Figure out a solution for compiling to common-js for unit testing