@babel/standalone
@babel/standalone
provides a standalone build of Babel for use in browsers and other non-Node.js environments.
When (not) to use @babel/standalone
If you're using Babel in production, you should normally not use @babel/standalone
. Instead, you should use a build system running on Node.js, such as Webpack, Rollup, or Parcel, to transpile your JS ahead of time.
However, there are some valid use cases for @babel/standalone:
- It provides an easy, convenient way to prototype with Babel. Using
@babel/standalone
, you can get started using Babel with just a simple script tag in your HTML. - Sites that compile user-provided JavaScript in real-time, like JSFiddle, JS Bin, the REPL on the Babel site, JSitor, etc.
- 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 modern ES provides.
- Other non-Node.js environments (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. This is a simple way to embed it on a webpage without having to do any other setup.
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
- Install it manually:
- npm
- Yarn
- pnpm
npm install --save @babel/standalone
yarn add @babel/standalone
pnpm add @babel/standalone