How zthxxx/react-dev-inspector works
Main Components
• Compiler Integration (Babel Plugin):
• Found under the “packages/babel-plugin” directory.
• Inspector Component:
• Located in the “packages/inspector” package.
• This React component, when integrated into your app, reads the saved source info.
• Dev Server Middleware:
• Located in “packages/middleware” and in the various integrations provided (e.g., packages/umi3-plugin, packages/umi4-plugin, packages/vite-plugin, etc.).
• These middlewares capture requests from the Inspector component and forward them appropriately.
• Launch Editor Endpoint:
• Under “packages/launch-editor-endpoint”.
• Responsible for receiving API requests and invoking your local IDE to open the specific file.
• Examples & Documentation:
• The “examples” folder shows integrations with various frameworks (CRA, Next.js, rspack, multiple versions of Umi and Vite). This emphasizes that the tool has been tailored for a wide range of React-based ecosystems.
• Build & Dev Tools:
• There are configuration files and scripts at the root (like .github workflows, PNPM configurations, and various project scripts) that manage building, versioning, and testing.
Relationships and Interactions
• The user interacts with the React application in the browser. Inside it, the Inspector component detects when a developer clicks on a component.
• The Inspector component uses the source mapping (possibly injected at build/compile time by the Babel plugin) to know the file location.
• It sends this source path via an API call to the dev server middleware.
• The middleware relays the request to the Launch Editor Endpoint, which then triggers the local IDE to open the file.
• The build tools and tooling (different bundlers or frameworks defined in various example integrations) show how this system integrates seamlessly with different environments.
Architectural Patterns/Design Principles
• Modular Design: Each feature (plugin, inspector, middleware, launch-editor) is kept in its own package. This separation makes it easy to maintain and extend.
• Middleware-Based Communication: The Inspector component’s API calls are handled by custom middleware in the dev server to bridge browser actions and local system actions.
• Extensibility: With plugins available for different bundlers (Webpack, Vite, rspack, Umi, CRA), the architecture is designed to be framework-agnostic.
• Integration Over Layers: The system clearly differentiates between compile-time (source injection), runtime (Inspector in the browser), and development tooling (middleware to open the IDE).
Relevant Technologies/Frameworks
• React: The core library since the tool targets React developers.
• Babel: For the compiler plugin that injects source mapping.
• Various dev server middleware integrations (specific to bundlers like Vite, rspack, etc.).
• Node.js and middleware frameworks on the dev-server side.
• GitHub actions and workflows are used to handle CI/CD.
Final Summary
• Follow this with a “React Application” node highlighting the Inspector Component.
• Link it to an “API/Middleware” layer (showing Dev Server Middleware) which communicates with the “Launch Editor Endpoint.”
• On the side, indicate the “Babel Plugin” which runs during build time and injects source info back into the React components.