Browser

How to transpile in the browser.

A browser version of babel is available from `browser.js` inside the babel directory in an 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.

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

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

API

Programmatically transpile 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 {}");