Browser

How to compile in the browser.

A browser version of Babel is available from browser.js inside a babel-browser npm release

Not intended for serious use

Compiling in the browser has a fairly limited use case, so if you are working on a production site you should be precompiling your scripts server-side. See setup build systems for more information.

Script tags

When the browser.js file is included all scripts with the type text/ecmascript-6 and text/babel are automatically compiled and run. There is also a browser.min.js.

<script src="node_modules/babel-browser/browser.js"></script>
<script type="text/babel">
class Test {
  test() {
    return "test";
  }
}

var test = new Test;
test.test(); // "test"
</script>

API

Programmatically compile and execute strings of ES6 code.

See options for additional documentation.

babel.transform(code, [opts])

babel.transform("class Test {}").code;

babel.run(code, [opts])

babel.run("class Test {}");