← Back to TypeScript Course | Chapter 25: Build Tools | Lesson 4 of 6

TypeScript के साथ ESBuild

esbuild एक बहुत fast JavaScript और TypeScript build tool है। यह TypeScript syntax को quickly transform कर सकता है, हालांकि type checking normally separately handle की जाती है।
Syntax
typescript
require("esbuild").build({
    entryPoints: ["src/index.ts"],
    bundle: true,
    outfile: "dist/bundle.js",
});

Core Concept

esbuild Go में लिखा एक bundler और transpiler है जो TypeScript को JavaScript में extremely fast compile करता है बिना खुद कोई type checking perform किए types strip करके — speed उस explicit tradeoff से आती है।

उदाहरण: Core Concept

typescript
// esbuild strips TypeScript types without checking them -- that's the speed tradeoff
console.log("esbuild transpiles fast by skipping type checking entirely");

Basic Setup

एक minimal setup एक छोटे Node script या सीधे esbuild CLI से esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, outfile: 'dist/bundle.js' }) call करता है, .ts files के लिए किसी loader configuration की ज़रूरत के बिना।

उदाहरण: Basic Setup

typescript
// esbuild.build({ entryPoints: ["src/index.ts"], bundle: true, outfile: "dist/bundle.js" });
console.log("No loader config needed -- esbuild handles .ts natively");

Typed Example

चूंकि esbuild सिर्फ types strip करता है और कभी check नहीं करता, एक typed example को फिर भी development के दौरान असल में type errors catch करने के लिए एक parallel tsc --noEmit run चाहिए (अक्सर एक separate terminal या CI step में)।

उदाहरण: Typed Example

typescript
// esbuild alone won't catch type errors -- pair with:
// tsc --noEmit
console.log("A parallel tsc --noEmit run is required for real type safety");

Project Usage

एक असली project में, esbuild commonly एक बड़े toolchain के अंदर fast transform step के रूप में उपयोग होता है (Vite इसे इस तरह उपयोग करता है) sole build tool के बजाय, exactly इसलिए क्योंकि यह raw speed के लिए type safety trade करता है।

उदाहरण: Project Usage

typescript
// Vite itself uses esbuild internally as its fast dev transform step
console.log("esbuild is often one part of a larger toolchain, not standalone");

Best Practices

Type safety के लिए कभी सिर्फ esbuild पर rely न करें — हमेशा इसे CI में tsc --noEmit के साथ pair करें, क्योंकि एक project source में असली type errors मौजूद होने पर भी esbuild के through successfully build और run हो सकता है।

उदाहरण: Best Practices

typescript
// package.json: "typecheck": "tsc --noEmit"  (run in CI)
console.log("Never rely on esbuild alone for type safety -- always pair with tsc");
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. esbuild से type errors report होने की उम्मीद करना, जब यह सिर्फ types strip करता है और कभी check नहीं करता।
  2. emitDecoratorMetadata पर rely करना, जिसे esbuild support नहीं करता।
  3. Files के across const enum उपयोग करना, क्योंकि esbuild हर file को अलग treat करता है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.