TypeScript के साथ ESBuild
In this page:
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
// 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
// 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
// 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
// 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
// package.json: "typecheck": "tsc --noEmit" (run in CI)
console.log("Never rely on esbuild alone for type safety -- always pair with tsc");
- esbuild से type errors report होने की उम्मीद करना, जब यह सिर्फ types strip करता है और कभी check नहीं करता।
emitDecoratorMetadataपर rely करना, जिसे esbuild support नहीं करता।- Files के across
const enumउपयोग करना, क्योंकि esbuild हर file को अलग treat करता है।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: