Empower growth and innovation with the latest Front-end Dev insights

In 2026, with #ifdefs all over Uni-app—hidden on App, shown in Mini Program, moved again on H5—is it still one codebase?

Nov 17, 2026 Read: 27

It counts as one codebase—but only if the differences are consolidated. In 2026 Uni-app projects, the test is not how many #ifdefs you wrote, but where they are written: if they are concentrated in platform capability wrappers, entry configuration, and a few style hooks, while business pages keep the same logic, it is still one codebase; if every page forks inside conditional compilation, and one requirement change means changing and testing it three times, then you are actually maintaining three codebases that happen to live in the same repository.

1. Why scattered #ifdefs turn one codebase into three

The essence of conditional compilation is compile-time pruning: code that does not belong to the current target is removed during packaging, so no branch check is produced at runtime. So the accurate description of Uni-app is “one source tree produces packages for multiple platforms,” not “one codebase runs the same logic on every target.” Pruning itself is not the problem; the problem is that once differences are scattered across every page, the cost of reading, changing, and regression testing multiplies by the number of targets.

A common project situation: the budget only covers one frontend developer, the three targets must launch one after another within about half a month, and assets are still waiting for client confirmation. To hit the deadline, conditional compilation is written directly into pages, and whoever needs a variant adds a block. As a result, when a sharing capability is added to the Mini Program at the last minute, the changes are scattered across six or seven pages, regression runs three rounds, and it costs two or three extra days compared with reserving an abstraction layer (experience range). This is not because the framework is bad; it is because the differences have no single owner, and every late addition repeats the same cost.

  • Two structures in the template: the same card is written once for App and once for the Mini Program; changing the copy means changing two places, and sooner or later one is missed.
  • Platform checks scattered around: platform identifier strings are used in business code; one wrong character does not throw an error, it just silently fails on one target.
  • Writing business code after getting only one target working: API wrappers are written only for H5 cross-origin habits, then rewritten during App integration testing.
  • Styles layered with hooks: a little added for this target, a little overridden for that one; six months later, nobody dares delete any of it.

2. A three-layer way to consolidate differences: confine multi-platform differences to a few files

This layering is based on “frequency of change”: platform capabilities change quickly but are limited in number, while business logic changes often but is largely the same across the three targets. Confine the fast-changing part to a few files, and business pages do not need to know which target they are running on; only then do personnel changes and stacked requirements avoid pulling in a whole area of code.

  1. Produce a difference list first: list login, payment, sharing, geolocation, scanning, upload, physical back, scrolling and sticky headers, safe area, fonts, and units one by one, and mark whether each is natively supported on the three targets, needs a fallback, or will not be done at all. Note that the list should be produced before work starts; adding it during integration testing usually means rework.
  2. Build a platform adaptation layer: provide a unified entry point for capabilities such as login, sharing, storage, and requests; pages call only the unified methods, and platform differences are written inside this layer. Note that input parameters and return structures must be aligned across the three targets, and failure reasons must be normalized; otherwise pages still have to determine the platform themselves.
  3. Drive styles with design tokens: define spacing, font size, corner radius, and safe area first, then cover platform differences with a small number of conditional styles; do not allow each page to write its own set. Note that token granularity down to the component level is enough—too fine-grained and nobody will maintain it.
  4. Write a three-target acceptance checklist: list checkpoints by target, and run the main flow plus at least one small-screen device for each target. Note that acceptance items must go into the delivery document; something said verbally is as good as unsaid.

After using this split, the signs of a qualified setup are concrete: platform-check strings cannot be found in business pages—they appear only in the adaptation layer; adding one platform capability changes one to two files on average (experience range); and the same small requirement does not need separate scheduling by target.

  • Name adaptation-layer interfaces by business action, not by platform, so it is not obvious at a glance that one is specific to a target.
  • Do not rush to wrap a one-off difference; extract it when it appears a second time. Premature abstraction also creates technical debt to repay.
  • Keep conditional compilation in the adaptation layer and entry configuration; if it appears in business components, the layering is not thorough enough.

3. Conditional compilation, an adaptation layer, or split-by-platform implementation?

Not every difference is worth wrapping. The criteria are reuse count and the cost of failure: for a small difference used only once, a block of conditional compilation is the lowest-cost option; for a capability that appears repeatedly across pages and versions, it is worth wrapping once; only modules with fundamentally different interaction models should be considered for splitting by target.

  • Scattered conditional compilation: a single-point change usually takes a few minutes, suitable for one-off scenarios such as showing or hiding a button or differing copy; as the number of pages grows, maintenance cost rises with page count, and the regression surface expands with it.
  • Adaptation-layer wrapping: initial investment is about half a day to two days (experience range, depending on the number of capability items), suitable for capabilities reused across pages such as login, payment, sharing, and requests; not suitable for features that appear on only one page.
  • Split-by-platform implementation or a separate repository: clearly higher cost, suitable for modules where one target needs native maps, complex gesture editing, or exclusive interactions; not suitable for splitting merely because styles, units, or safe areas differ.

A boundary judgment that can be excerpted on its own: when platform differences are concentrated in two or three capability items, one Uni-app codebase is usually more cost-effective; when most pages need different interactions and layouts, splitting by target or using separate repositories often has a lower long-term cost. Differences that are purely about styles, units, and safe areas can be solved with design tokens plus a few style hooks—there is no need to escalate to splitting by target.

4. What counts as passing acceptance before release

Acceptance criteria must be testable, not “it looks about right.” Under common 2026 delivery practices, run the main flow on each of the three targets, plus one permission-denied case and one weak-network case, then check the layout on a small-screen Android device; this basically catches most online issues.

Commonly missed points on each of the three targets

  • App: where the physical back key goes, the fallback page after a permission is denied, and package updates and cache clearing—these three cannot be tested in the Mini Program.
  • Mini Program: main package size, the title and image of the share card, and the order of authorization pop-ups versus business requests; if the order is wrong, review rejection becomes likely.
  • H5: whether the first-screen body content is in the source, whether refreshing a child route returns 404, and whether the API domain and cross-origin settings are configured correctly.

The pass line can be defined this way: the main flow works on every target; permission denial and network failure produce clear messages; the back key does not directly exit the app; and on long copy and small-screen devices, buttons do not overlap or get pressed under the safe area. If it does not meet this, do not release yet—online fixes for such issues usually cost more than checking before release. Based on experience range, one round of a three-target acceptance checklist takes about half a day to one day, far cheaper than an online rollback.

5. Applicable scenarios and boundaries

Suitable cases: the three targets share the same business model and have similar interaction patterns; the team has one to three people and no capacity to maintain three codebases; and the release cadence is similar across targets, with differences mainly in capability integration rather than page structure. In this combination, consolidating differences into an adaptation layer makes the benefit of one source tree fairly obvious; Xiyue Company also often uses this division of work in website building and multi-platform delivery.

Unsuitable cases: one target has a heavy-interaction module, such as real-time maps, complex gesture editing, or scenarios requiring deep hardware access; or you are building only two targets whose interaction models are already different—forcing them into one codebase will fill the code with exceptions. In such cases, splitting modules by target and sharing the rest is often cheaper than full unification. Note that “splitting by module” does not mean rewriting the whole project; the criteria are whether the module changes frequently and whether the cost of failure is high.

Frequently asked questions

Do too many #ifdefs bloat the installation package?

Code written in target-specific files is pruned at compile time and does not enter other targets' packages; but if platform checks are written as runtime branches, that logic stays in the package, and both size and branch cost must be counted.

Is the adaptation layer just another wrapper around requests?

No. Requests are only one item; login state, sharing, storage, permissions, and physical back should also go through the same entry point. Otherwise differences will still leak from pages, and the wrapper might as well not exist.

Should a one-person team still build an adaptation layer?

Build a minimal version: wrap only login, requests, and storage, and use conditional compilation for the rest; extract a capability when it is reused a second time, avoiding abstraction for its own sake.

Is it reliable to determine the platform with the system information API?

It works, but compile-time constants are more stable because they do not depend on the runtime environment. Runtime checks are suitable for fallback scenarios that need to distinguish different versions of the same target; the trade-off is whether you need to distinguish versions.


If an existing project already has conditional compilation scattered across pages, spend half a day producing a difference list first, extract capabilities reused more than once into the adaptation layer, then add a three-target acceptance checklist. When time is tight, prioritize login, requests, and physical back. If the three targets already have different interaction models, do not force them into one codebase; splitting by module and sharing the rest is more prudent.

Have a similar project in mind?
Contact us for a one-to-one project reference proposal
Obtain Proposal
Interested in this topic?
10-year tech team — reference proposal within 24 hours
Obtain Proposal
Are you ready?
Then reach out to us!
+86-13370032918
Discover more services, feel free to contact us anytime.
Please fill in your requirements
What services would you like us to provide for you?
Your Budget
ct.
Our WeChat
Professional technical solutions
Phone
+86-13370032918 (Manager Jin)
The phone is busy or unavailable; feel free to add me on WeChat.
E-mail
349077570@qq.com
Submitted successfully
Thank you for your trust. We will contact you soon!
Recommended projects for you