Babel JavaScript Transpiler

Paste modern JavaScript, JSX or TypeScript and compile it for older browsers with the real Babel loaded on request, preset-env targets, the React and TypeScript presets and source maps, or with a small built-in engine that works offline.

ทำงานในเบราว์เซอร์ของคุณ ไฟล์ไม่ออกจากอุปกรณ์ ดูวิธีตรวจสอบ

…

วิธีทำ

  1. 1
    Add source

    Paste code, open a .js, .jsx, .ts or .tsx file or load one of the three samples.

  2. 2
    Set targets

    Type a Browserslist query or pick a common target for preset-env.

  3. 3
    Choose presets

    Turn JSX and TypeScript on or off and set the JSX runtime and pragma.

  4. 4
    Pick the engine

    Use the built-in engine offline or load Babel 7.29.13 for the full compiler.

  5. 5
    Compare

    Read the source and output side by side and check any lines left as written.

  6. 6
    Download

    Save the compiled file and its source map, copy the output or the Babel config.

เกี่ยวกับเครื่องมือนี้

Babel is the compiler most JavaScript projects use to turn new syntax into code that older browsers understand, to compile JSX into function calls and to remove TypeScript types. This page runs it without a build setup. Press the load button and @babel/standalone version 7.29.13, about 3.2 MB, downloads once from jsDelivr; after that every edit is compiled within a moment in the browser, with the source on the left and the output on the right. The preset-env stage takes a Browserslist target such as defaults, ie 11 or chrome >= 60, safari >= 12 and applies only the transforms those browsers need. The React preset compiles JSX with the classic createElement runtime and your own pragma, or with the automatic react/jsx-runtime imports. The TypeScript preset strips types, interfaces and type-only imports and compiles enums. You can keep ES modules or turn them into CommonJS, minify, drop comments, and produce a source map either as a separate .map file or inlined in the output. Errors come back with their line and column. Before Babel is loaded, or when you are offline, a built-in engine written for this page handles the everyday cases: JSX, type annotations, interfaces, type aliases, enums, generics, as casts and non-null marks, arrow functions, template literals, let and const, shorthand properties and methods, the exponent operator, nullish coalescing and optional chaining. Anything it leaves untouched, such as classes or async functions, is listed with its line number.

Syntax versus polyfills

A transpiler rewrites syntax: an arrow function becomes a function expression, a template literal becomes string concatenation, optional chaining becomes a null check. It does not add missing built-in objects or methods. Code that calls Promise, fetch, Array.prototype.includes or Object.entries still fails in a browser that never had them, which is why projects pair Babel with polyfills from core-js. The details panel shows the exact Babel options used and lets you download them as a babel.config.json, so you can reproduce the same output in a real build.

Worked example

Load the modern JavaScript sample and keep the built-in engine at ES5. The line const area = (r) => Math.PI * r ** 2; becomes var area = function (r) { return Math.PI * Math.pow(r, 2); };. The optional chain and default user?.address?.city ?? "unknown" becomes a null check on user and on user.address before reading city, wrapped in a != null test that falls back to "unknown". The template literal becomes ("" + (user.name) + " lives in " + (city)), the shorthand return object becomes { note: note, area: area(user.size), toString: function () { return note; } }, and the map callback becomes a function expression. The engine lists eight kinds of change and reports nothing left untransformed, so the file runs as written in an ES5 browser.

Limits

The built-in engine is deliberately small: it does not compile classes, async functions, generators, destructuring, spread or modules, and its TypeScript stripping covers common annotations, not every type-level construct. Load Babel for complete and exact output. Neither engine adds polyfills, and loading Babel needs an internet connection the first time.

ตัวอย่างพร้อมวิธีทำ

ES5 built-in: r ** 2 becomes Math.pow(r, 2), arrows become function expressions, ?? and ?. become null checks.

สรุปสั้น ๆ

คำถามที่พบบ่อย

Is this the official Babel?

When you press Load Babel, yes: the official @babel/standalone package, pinned to version 7.29.13 and served by jsDelivr. The built-in engine is a separate small transpiler written for this page so that it works offline.

What targets should I use?

defaults is a sensible choice for public websites. Use a query such as chrome >= 80, safari >= 14 when you know your users, or ie 11 if you must support Internet Explorer, which turns on almost every transform.

Why does my output still contain import and export?

Modules are kept by default because bundlers and modern browsers understand them. Choose CommonJS under Modules to get require and module.exports for Node or older tools.

How do I get a source map?

Tick Source map. With Babel loaded, download the .map file separately or tick Inline the map to embed it in the output as a data URL. The built-in engine does not produce source maps.

Does it type-check my TypeScript?

No. Babel and the built-in engine only remove types; they never report type errors. Run the TypeScript compiler with tsc --noEmit for type checking.

Is my code sent to a server?

No. Both engines run in this page. Loading Babel downloads the compiler from jsDelivr, but your source stays in the browser and is saved only in local storage.

ฟรีทั้งหมดไม่มีค่าใช้จ่าย ไม่ต้องสมัคร
ไฟล์เป็นส่วนตัวทุกอย่างทำงานในเบราว์เซอร์ของคุณ
ใช้ง่ายในภาษาของคุณมีหลายภาษา