tiny-babel-standalone
v1.0.0
Published
> Fork: this project is fork from my-babel-standalone, and want to build a tiny babel-standalone to be used in browser. It exports UMD, you can use modular import or use directly in browser. It did not contain plugins and presets, if you want to include @
Downloads
2
Readme
tiny-babel-standalone
Fork: this project is fork from my-babel-standalone, and want to build a tiny babel-standalone to be used in browser. It exports UMD, you can use modular import or use directly in browser. It did not contain plugins and presets, if you want to include @babel/preset-env or any other plugins, you should clone this project and invoke
registerPlugins
andregisterPresets
to add them.
This standalone build uses @babel/preset-env, @babel/polyfill, and whatwg-fetch to create an experience that mirrors modern browsers. It does not include presets for flow, react, and typescript.
- @babel/standalone = 5-6 mb minified
- my-babel-standalone = 1.5 mb minified
- tiny-babel-standalone = 1mb without plugins and presets, parser+generate 610kb
Currently, it's being used in the latest builds of modern-hta.
Usage
<script src="https://unpkg.com/tiny-babel-standalone"></script>
<script>
const {
version,
parse,
traverse,
types,
generate,
availablePlugins,
availablePresets,
buildExternalHelpers,
registerPlugin,
registerPlugins,
registerPreset,
registerPresets,
transform,
transformFromAst,
} = Babel
const ast = parse(code, {
tokens: true,
sourceType: 'unambiguous',
})
traverse(ast, {
...
})
const newCode = generate(ast, {
...
})
</script>
<script src="https://unpkg.com/tiny-babel-standalone/dist/parser.min.js"></script>
<script>
const {
version,
parse,
types,
generate,
} = Babel
const ast = parse(code, {
tokens: true,
sourceType: 'unambiguous',
})
const newCode = generate(ast, {
...
})
</script>