All Projects → babel → Babel Standalone

babel / Babel Standalone

Licence: mit
🎮 Now located in the Babel repo! Standalone build of Babel for use in non-Node.js environments, including browsers.

Programming Languages

javascript
184084 projects - #8 most used programming language
es6
455 projects
es2015
71 projects

Labels

Projects that are alternatives of or similar to Babel Standalone

Lyo
📦 Node.js to browser - The easy way
Stars: ✭ 624 (-22.58%)
Mutual labels:  babel
Presspack
💻 Wordpress like it's 2020 with Webpack and Docker
Stars: ✭ 658 (-18.36%)
Mutual labels:  babel
React Article Bucket
总结,积累,分享,传播JavaScript各模块核心知识点文章全集,欢迎star,issue(勿fork,内容可能随时修改)。webpack核心内容部分请查看专栏: https://github.com/liangklfangl/webpack-core-usage
Stars: ✭ 750 (-6.95%)
Mutual labels:  babel
Pizzaql
🍕 Modern OSS Order Management System for Pizza Restaurants
Stars: ✭ 631 (-21.71%)
Mutual labels:  babel
Serverless Typescript Starter
🗄🙅‍♀️ Deploy your next serverless JavaScript function in seconds
Stars: ✭ 653 (-18.98%)
Mutual labels:  babel
React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (-15.88%)
Mutual labels:  babel
React App
Create React App with server-side code support
Stars: ✭ 614 (-23.82%)
Mutual labels:  babel
Minimal React Webpack Babel Setup
The minimal React, Webpack, Babel Setup. You want to get beyond create-react-app?
Stars: ✭ 777 (-3.6%)
Mutual labels:  babel
React Isomorphic Boilerplate
🌟 An universal React isomorphic boilerplate for building server-side render web app.
Stars: ✭ 653 (-18.98%)
Mutual labels:  babel
Preset Modules
A Babel preset that targets modern browsers by fixing engine bugs (will be merged into preset-env eventually)
Stars: ✭ 730 (-9.43%)
Mutual labels:  babel
Website
🌐 The Babel documentation website
Stars: ✭ 631 (-21.71%)
Mutual labels:  babel
Slinky
A light-weight, responsive, mobile-like navigation menu plugin
Stars: ✭ 649 (-19.48%)
Mutual labels:  babel
Nylas Mail
💌 An extensible desktop mail app built on the modern web. Forks welcome!
Stars: ✭ 24,653 (+2958.68%)
Mutual labels:  babel
Cordova Template Framework7 Vue Webpack
Framework7 - Vue - Webpack Cordova Template with Webpack Dev Server and Hot Module Replacement
Stars: ✭ 630 (-21.84%)
Mutual labels:  babel
Generator Angular Fullstack
Yeoman generator for an Angular app with an Express server
Stars: ✭ 6,135 (+661.17%)
Mutual labels:  babel
Express Babel
Express starter kit with ES2017+ support, testing, linting, and code coverage
Stars: ✭ 621 (-22.95%)
Mutual labels:  babel
Sagui
🐒 Front-end tooling in a single dependency
Stars: ✭ 676 (-16.13%)
Mutual labels:  babel
React Things
Коллекция материалов для изучения React
Stars: ✭ 789 (-2.11%)
Mutual labels:  babel
Awesome Babel
😎A list of awesome Babel plugins, presets, etc.
Stars: ✭ 770 (-4.47%)
Mutual labels:  babel
Blog
Here is my blog
Stars: ✭ 714 (-11.41%)
Mutual labels:  babel

babel-standalone is now part of babel! Go check it out ⚠️⚠️⚠️⚠️

babel-standalone

babel-standalone is a standalone build of Babel for use in non-Node.js environments, including browsers. It's bundled with all the standard Babel plugins and presets, and a build of babili (babel-minify) is optionally available too.

But why?!

It's true that using Babel through Webpack, Browserify or Gulp should be sufficient for most use cases. However, there are some valid use cases for babel-standalone:

  • Sites like JSFiddle, JS Bin, the REPL on the Babel site, etc. These sites compile user-provided JavaScript in real-time.
  • Apps that embed a JavaScript engine such as V8 directly, and want to use Babel for compilation
  • Apps that want to use JavaScript as a scripting language for extending the app itself, including all the goodies that ES2015 provides.
  • Integration of Babel into a non-Node.js environment (ReactJS.NET, ruby-babel-transpiler, php-babel-transpiler, etc).

Installation

There are several ways to get a copy of babel-standalone. Pick whichever one you like:

  • Use it via UNPKG: https://unpkg.com/[email protected]/babel.min.js. This is a simple way to embed it on a webpage without having to do any other setup.
  • Install via Bower: bower install babel-standalone
  • Install via NPM: npm install --save babel-standalone
  • Manually grab babel.js and/or babel.min.js from the GitHub releases page. Every release includes these files.
  • Install it via Git: You can use the repo at https://github.com/Daniel15/babel-standalone-bower to pull a prebuilt version from Git. Note that this is generally only advised for systems that must pull artifacts from Git, such as Bower.

Usage

Load babel.js or babel.min.js in your environment. This will expose Babel's API in a Babel object:

var input = 'const getMessage = () => "Hello World";';
var output = Babel.transform(input, { presets: ['es2015'] }).code;

When loaded in a browser, babel-standalone will automatically compile and execute all script tags with type text/babel or text/jsx:

<div id="output"></div>
<!-- Load Babel -->
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<!-- Your custom script here -->
<script type="text/babel">
const getMessage = () => "Hello World";
document.getElementById('output').innerHTML = getMessage();
</script>

You can use the data-plugins and data-presets attributes to specify the Babel plugins/presets to use:

<script type="text/babel" data-presets="es2015,stage-2">

Loading external scripts via src attribute is supported too:

<script type="text/babel" src="foo.js"></script>

Note that .babelrc doesn't work in babel-standalone, as no file system access is available. The presets and/or plugins to use must be specified in the options passed to Babel.transform.

Customisation

Custom plugins and presets can be added using the registerPlugin and registerPreset methods respectively:

// Simple plugin that converts every identifier to "LOL"
function lolizer() {
  return {
    visitor: {
      Identifier(path) {
        path.node.name = 'LOL';
      }
    }
  }
}
Babel.registerPlugin('lolizer', lolizer);

Once registered, just use the name of the plugin:

var output = Babel.transform(
  'function helloWorld() { alert(hello); }',
  {plugins: ['lolizer']}
);
// Returns "function LOL() { LOL(LOL); }"

Custom plugins also work for inline <script>s:

<script type="text/babel" data-plugins="lolizer">

Manually Building

If you want to manually upgrade the Babel version used by babel-standalone (or build your own release), follow these steps:

  1. Upgrade the Babel versions in package.json. This can be done with npm-check-upgrades (eg. npm-check-updates -u -a --packageFile ./package.json /^babel\-/)
  2. Delete node_modules, as npm often produces inefficient directory layouts if you upgrade in-place
  3. Run npm install && npm run build
  4. Run npm run test to ensure it works
  5. Open examples/example.htm and ensure it works
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].