Vite Build Outputs, Reborn as HAP, HAR, HSP on HarmonyOS
Anyone shipping to HarmonyOS devices needs to know that HAR copies itself into every consumer, while HSP stays single-instance in memory and on disk. Mistaking them bloats the .app or breaks runtime sharing, and the rules for dependency visibility and resource paths differ enough from npm/Webpack habits to cause silent bugs.
HarmonyOS's packaging pipeline mirrors what Vite does when it splits a bundle: an entry point, route chunks, and shared vendor code. But the artifact names change, and the rules are stricter. The entry is an entry-type HAP, optional business blocks become feature-type HAPs, and shared code comes in two flavors. HAR is a static archive that gets compiled into every consuming module, so each consumer carries its own copy. HSP is a dynamic shared package that stays as one file in the .app and loads once per process.
Those two options answer the same question a Vite developer solves with manualChunks: where does the duplicate code go? HAR is the default for a single-module project, like components and utilities inside one HAP. HSP is the right call when multiple HAPs reference a large piece of business code, resources, or native .so files, because it only exists once in the final bundle. The trade-off is explicit: HSP increases build time and memory because more language-compilation tasks get triggered, so small utilities stay in HAR.
The guide also walks through the quirks a Vue dev will hit: HSP dependencies don't propagate transitively (A depends on B, B on C, but A cannot import from C), and resource paths inside HSP are resolved relative to the caller, not the file writing them, so you need $r() and an exported manager class. An integration-state HSP exists for sharing across multiple apps within one organization; it holds no bundleName at build time and gets re-signed with the host's identity when consumed.
The hardest boundary for a Vite developer is that HAR's duplication is invisible after compilation: you only feel it as package bloat, while HSP's deduplication comes with a measurable compile-time and memory penalty.
The article's resource-path rule inverts a core Webpack/Vite intuition: a relative path in an HSP file does not resolve from that file, but from the caller, so $r() is not a suggestion but a requirement.
The integration-state HSP is the rare packaging mechanism designed specifically for cross-app sharing; it exists because the strict bundleName binding of normal HSPs made another option necessary.