babel/doc/usage/browser.md
2015-01-05 23:27:46 -08:00

1.2 KiB

layout title description permalink redirect_from
docs Browser How to transpile in the browser. /docs/usage/browser/ /browser.html

A browser version of 6to5 is available from `browser.js` inside the 6to5 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/6to5 are automatically compiled and ran.

<script src="node_modules/6to5/browser.js"></script>
<script type="text/6to5">
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.

to5.transform(code, [opts])

to5.transform('class Test {}').code;

to5.run(code, [opts])

to5.run('class Test {}');