1.0.0 • Published 3 years ago

tiny-babel-standalone v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

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 and registerPresets 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.

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>