Webpack: Module Bundling और Build Optimization कोर्स के 31 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।
मॉड्यूल 10: पुनरावलोकन
20. एक common Webpack pitfall क्या है?
- बहुत सारे loaders का उपयोग करना।
- Minification हमेशा खराब है।
- Wrong loader order transformation failures cause करता है।
- CI में builds चलाना।
जवाब देखें
जवाब: Wrong loader order transformation failures cause करता है।
Loader order critical है क्योंकि वे right-to-left execute होते हैं, और incorrect order transformation pipeline को break करता है।
पाठ: Common pitfalls और solutions
21. Build performance को कैसे measure करें?
- Bundle में files की संख्या count करें।
- Build के दौरान console logs check करें।
- साथियों से पूछना कि build कितना लंबा लगता है।
- --profile flag या speed-measure-webpack-plugin का उपयोग करें।
जवाब देखें
जवाब: --profile flag या speed-measure-webpack-plugin का उपयोग करें।
--profile flag और speed-measure-webpack-plugin प्रत्येक build step के लिए detailed timing information provide करते हैं।
पाठ: Performance monitoring और profiling
22. आपको Webpack के बजाय Vite का उपयोग कब करना चाहिए?
- Fast dev experience के साथ simpler projects के लिए।
- जब आपको maximum customization की जरूरत हो।
- केवल production builds के लिए।
- जब आपको Internet Explorer 6 support करना हो।
जवाब देखें
जवाब: Fast dev experience के साथ simpler projects के लिए।
Vite native ESM के साथ fast development experience में excel करता है। Webpack extensive customization की जरूरत वाले projects के लिए बेहतर है।
पाठ: Alternative bundlers और migration
23. एक configuration को production-ready क्या बनाता है?
- सबसे बड़े bundle size का उपयोग करना।
- Minification, sourcemaps, caching, code splitting।
- सभी optimizations को disable करना।
- Hard-coded absolute paths और बिना hashing।
जवाब देखें
जवाब: Minification, sourcemaps, caching, code splitting।
Production-ready configs minification, code splitting, sourcemaps के through performance, caching को optimize करते हैं।
पाठ: Real-world applications और best practices
24. Dependency graph बनाना Webpack कहाँ से शुरू करे, यह कौन-सा option बताता है?
- output
- entry
- resolve
- devtool
जवाब देखें
जवाब: entry
Entry point वह root है जहाँ से Webpack imports को follow करता है।
पाठ: Real-world applications और best practices
25. Rule के use array में CSS को सही तरह process करने वाला loader order कौन-सा है?
- ['css-loader', 'style-loader']
- ['style-loader', 'css-loader']
- ['css-loader'] only
- ['babel-loader', 'style-loader']
जवाब देखें
जवाब: ['style-loader', 'css-loader']
Loaders right-to-left चलते हैं, इसलिए css-loader पहले parse करता है और style-loader result inject करता है।
पाठ: Real-world applications और best practices
26. Loader और plugin में मुख्य अंतर क्या है?
- Loaders hook into the whole build lifecycle; plugins transform single files.
- Loaders transform individual files; plugins hook into the build lifecycle.
- Plugins run only in development.
- There is no difference.
जवाब देखें
जवाब: Loaders transform individual files; plugins hook into the build lifecycle.
Loaders file type के अनुसार काम करते हैं; plugins बड़े build tasks संभालते हैं।
पाठ: Real-world applications और best practices
27. Production bundle से unused exports कौन-सी technique हटाती है?
- Tree-shaking
- Hot module replacement
- Source mapping
- Aliasing
जवाब देखें
जवाब: Tree-shaking
Tree-shaking static ES module imports के आधार पर dead code हटाती है।
पाठ: Real-world applications और best practices
28. भारी module को केवल तब कैसे load करें जब user को उसकी जरूरत हो?
- Use a dynamic import()
- Use a static import at the top
- Set mode to development
- Rename the entry file
जवाब देखें
जवाब: Use a dynamic import()
Dynamic import() अलग chunk बनाता है जो जरूरत पड़ने पर load होता है।
पाठ: Real-world applications और best practices
29. Output filenames में [contenthash] क्यों उपयोग करें?
- It encrypts the bundle.
- It changes only when content changes, enabling long-term caching.
- It speeds up the dev server.
- It enables source maps.
जवाब देखें
जवाब: It changes only when content changes, enabling long-term caching.
Unchanged file का नाम वही रहता है, इसलिए browsers cached copy reuse करते हैं।
पाठ: Real-world applications और best practices
30. webpack-dev-server में HMR क्या करता है?
- Minifies code on save.
- Replaces changed modules without a full page reload.
- Uploads source maps to production.
- Splits vendor chunks.
जवाब देखें
जवाब: Replaces changed modules without a full page reload.
HMR बदले हुए modules को उसी जगह बदलता है और application state बनाए रखता है।
पाठ: Real-world applications और best practices
31. Bundle बड़ा होने का कारण खोजने में कौन-सा tool मदद करता है?
- webpack-bundle-analyzer
- html-webpack-plugin
- css-loader
- fork-ts-checker-webpack-plugin
जवाब देखें
जवाब: webpack-bundle-analyzer
Analyzer bundle की composition दिखाता है, जिससे बड़ी dependencies आसानी से दिखती हैं।
पाठ: Real-world applications और best practices