Project References की जानकारी
In this page:
{
"references": [{ "path": "../other-project" }]
}
Basic Project Reference
references property एक TypeScript project की config से दूसरे project की config की ओर point करती है, एक बड़े codebase को छोटे, independently-buildable pieces में split होने देते हुए जो अब भी एक-दूसरे के against type-check करते हैं।
उदाहरण: Basic Project Reference
// app/tsconfig.json
// { "references": [{ "path": "../shared" }] }
console.log("references points from one project's config to another's");
Referenced Project Configuration
एक referenced project को एक compatible configuration चाहिए, सबसे ज़्यादा ज़रूरी composite: true, ताकि TypeScript compiler उस declaration output generate कर सके जिसपर इसे reference करने वाले दूसरे projects depend करेंगे।
उदाहरण: Referenced Project Configuration
// shared/tsconfig.json
// { "compilerOptions": { "composite": true, "declaration": true } }
console.log("composite: true lets other projects depend on this one's output");
Application और Library Projects
एक common structure reusable library code को उसे consume करने वाली application से अपने ही referenced project में अलग करता है, ताकि library को कुछ हद तक independently build, test, और version किया जा सके।
उदाहरण: Application and Library Projects
// packages/lib/tsconfig.json (composite: true)
// packages/app/tsconfig.json references: [{ path: "../lib" }]
console.log("Library and app split into separately buildable projects");
Referenced Projects Build करना
TypeScript का build mode (tsc -b) project references समझता है और referenced projects को सही dependency order में अपने आप build करता है, जो projects last build के बाद से नहीं बदले उन्हें skip करते हुए।
उदाहरण: Building Referenced Projects
// tsc -b
console.log("tsc -b builds referenced projects in correct dependency order");
Project References के फायदे
Project references बड़े codebases पर concerns separate करके, unnecessary recompilation कम करके, और packages के बीच dependency graph को shared node_modules के through implicit के बजाय explicit बनाकर फायदा देती हैं।
उदाहरण: Benefits of Project References
// Faster incremental builds, clear dependency graph, separated concerns.
console.log("Project references scale TypeScript to large, multi-package codebases");
- एक project reference करना जो
compositeनहीं है, जो एक error है। - Plain
tscचलाना बजायtsc -bके, इसलिए referenced projects पहले build नहीं होते। pathको किसी source file की ओर point करना बजाय referenced project के folder याtsconfig.jsonके।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: