Skip to content

Instantly share code, notes, and snippets.

@g-patel
Last active April 20, 2016 21:23
Show Gist options
  • Save g-patel/e7bb20108fccdf6dfb658ee3bddeefe3 to your computer and use it in GitHub Desktop.
Save g-patel/e7bb20108fccdf6dfb658ee3bddeefe3 to your computer and use it in GitHub Desktop.
Bable transpiles ES6 modules to CommonJS modules
C02Q10QCG8WM:~ gpatel$ ./node_modules/.bin/babel -d ~/tmp/es5-compiled --presets es2015 ~/tmp/lib.js ~/tmp/main.js
/Users/gpatel/tmp/lib.js -> /Users/gpatel/tmp/es5-compiled/Users/gpatel/tmp/lib.js
/Users/gpatel/tmp/main.js -> /Users/gpatel/tmp/es5-compiled/Users/gpatel/tmp/main.js
C02Q10QCG8WM:~ gpatel$ cat ~/tmp/lib.js ~/tmp/main.js ~/tmp/es5-compiled/Users/gpatel/tmp/*
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.square = square;
exports.diag = diag;
var sqrt = exports.sqrt = Math.sqrt;
function square(x) {
return x * x;
}
function diag(x, y) {
return sqrt(square(x) + square(y));
}'use strict';
var _lib = require('lib');
console.log((0, _lib.square)(11)); // 121
console.log((0, _lib.diag)(4, 3)); // 5C02Q10QCG8WM:~ gpatel$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment