chameleon
🦎 一套代码运行多端,一端所见即多端所见
A JavaScript framework by Didi that lets you write one codebase and deploy it as a website, WeChat mini-program, iOS app, Android app, and several other platforms simultaneously.
Chameleon (shortened to CML) is an open-source framework built by Didi, the Chinese ride-sharing company, that lets developers write a single codebase and have it run across many different platforms at once. The platforms it targets include regular websites, WeChat mini-programs, Alipay mini-programs, Baidu mini-programs, QQ mini-programs, ByteDance mini-programs, Android apps, iOS apps, and QuickApp (a standard from Android phone manufacturers). The name comes from the reptile that changes color to match its environment, which is what the framework does for your code.
The core idea is that building the same feature for each platform separately is expensive and exhausting. If a product team needs to ship a feature on a website and five different mini-program platforms, they would normally write and maintain five versions. Chameleon collapses that into one.
The development language it defines is called CML, alongside its styling language CMSS and standard JavaScript. The syntax was designed to feel familiar to anyone who has done web development. The markup structure works similarly to HTML, the styling is close to CSS, and the component model and data-binding system are deliberately close to Vue, a popular web framework. This means a developer who knows Vue can get started without learning an entirely new system.
A key design feature is what the project calls a polymorphism protocol. This handles the reality that platforms are not identical. When a difference exists between, say, WeChat and a standard website, the protocol gives developers a clean way to write platform-specific code for just that piece while keeping everything else shared. The idea is that you rarely need a total rewrite for each platform, only small adjustments in specific spots.
The framework also includes a library of ready-made UI components such as buttons, radio inputs, checkboxes, dialogs, and loading indicators, as well as a set of built-in API methods covering network requests, local storage, location, and animation. The full source code lives across the chameleon-team GitHub organization, with this main repository containing the build-time tooling.
Where it fits
- Write a product feature once in CML and ship it simultaneously on WeChat, Alipay, Baidu, QQ, ByteDance mini-programs, plus web.
- Replace five separate mini-program codebases with a single shared CML codebase, reducing maintenance burden.
- Use platform-specific overrides via the polymorphism protocol only where platforms truly differ, keeping the rest of the code shared.
- Build a cross-platform UI using the built-in button, dialog, and form components without writing platform-specific markup.