How tencent/wujie works
Based on our analysis of the file structure and the README documentation, the project “wujie” is a micro front-end framework that leverages Web Components along with iframes to provide a highly isolated and performant solution for integrating independent sub-applications into a main host. The project is set up as a monorepo and contains several packages (core functionality and framework-specific wrappers) as well as a comprehensive set of examples for various frontend frameworks (Angular, React, Vue, etc).
Main Components
• Core Engine (wujie-core): This package (located in packages/wujie-core) is the backbone of the framework. It implements the core APIs, lifecycle management, sandboxing (iframe and shadow DOM based isolation), event handling, and various utilities. Key modules include event management, proxy handling, and isolation mechanisms.
• Framework Integrations: Separate packages (e.g., wujie-react, wujie-vue2, wujie-vue3) provide integrations/wrappers for popular frontend frameworks. They allow developers to easily embed the micro-apps in their projects using idiomatic components.
• Examples/Demos: The “examples” folder contains multiple sample applications for various frameworks (Angular12, main-react, react16, react17, vite, vue2, vue3). These are representative of how the main framework (wujie) is consumed and integrated.
• Documentation & DevOps: The docs folder, along with configuration files (e.g., .github workflows, commit lint settings, husky hooks), represents the support system for documentation, continuous integration, and release management.
Relationships and Interactions
• Main Application / Host: The micro front-end host loads the sub-applications into isolated iframes or via Web Components. The host interacts with the core engine (wujie-core) to initialize and manage sub-app lifecycles.
• Core and Framework Wrappers: The core engine provides a standard API (e.g., startApp, preloadApp, destroyApp) and the wrapper packages (for React, Vue) encapsulate these API calls so that they can be easily integrated into framework-specific applications.
• Communication: There is a two-way communication mechanism between the host and sub-applications. This includes lifecycle hooks and decentralized communication channels that facilitate data sharing and synchronization across boundaries.
• Build & Deployment: The project includes scripts (in the “scripts” folder and configuration files in the root and .github directories) that facilitate local development, testing, and building of both the core engine and the sample applications.
Important Architectural Patterns and Principles
• Isolation via iframe and Web Components: This is a key principle ensuring that the sub-applications are sandboxed with separate window and document objects.
• Plugin and Lifecycle Management: The framework’s extensibility (through its plugin system) and strict lifecycle hooks are important architectural features.
• Monorepo Structure: Using tools like pnpm and a lerna.json file allows for consolidated dependency management across multiple packages.
• Framework Adapter Pattern: Specialized packages for React, Vue, etc., demonstrate an adapter pattern that abstracts core functionalities into components that align with the developer’s ecosystem.
Depicting the Technologies and Frameworks
• That the core uses modern JavaScript/TypeScript practices with supportive tooling like Babel, ESLint, and Webpack.
• The examples and wrappers reflect usage in Angular, React, Vue, and Vite environments, which might be illustrated as separate nodes or modules connected to the core.
• Continuous integration using GitHub workflows and Husky hooks, which ensures code quality and proper commit messages.