22 Star 123 Fork 28

DiDi-opensource/mpx

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

mpx-logo

Mpx, 一款具有优秀开发体验和深度性能优化的增强型跨端小程序框架。

test-status docs-status

官网及文档

欢迎访问https://mpxjs.cn,跟随我们提供的文档指南使用Mpx进行跨端小程序开发。

近期更新

基于 Mpx 的移动端基础组件库 mpx-cube-ui 已经开源,更多详情查看这里

Mpx 2.9 版本正式发布,支持原子类、SSR和构建产物体积优化,更多详情查看这里,迁移指南查看这里,相关指南及 API 参考文档已更新。

简介

Mpx是一款致力于提升小程序开发体验和用户体验的增强型小程序跨端框架,通过Mpx,我们能够以类Vue的开发体验高效优雅地构筑出高性能跨端小程序应用,在所有开放的小程序平台及web平台中运行。

Mpx具有以下功能特性:

快速开始

# 安装mpx脚手架工具
npm i -g @mpxjs/cli

# 初始化项目
mpx create mpx-project

# 进入项目目录
cd mpx-project

# 安装依赖
npm i

# development
npm run serve

# production
npm run build

使用小程序开发者工具打开项目文件夹下dist中对应平台的文件夹即可预览效果。

使用示例

<template>
  <!--动态样式-->
  <view class="container" wx:style="{{dynamicStyle}}">
    <!--数据绑定-->
    <view class="title">{{title}}</view>
    <!--计算属性数据绑定-->
    <view class="title">{{reversedTitle}}</view>
    <view class="list">
      <!--循环渲染,动态类名,事件处理内联传参-->
      <view wx:for="{{list}}" wx:key="id" class="list-item" wx:class="{{ {active:item.active} }}"
            bindtap="handleTap(index)">
        <view>{{item.content}}</view>
        <!--循环内部双向数据绑定-->
        <input type="text" wx:model="{{list[index].content}}"/>
      </view>
    </view>
    <!--自定义组件获取实例,双向绑定,自定义双向绑定属性及事件-->
    <custom-input wx:ref="ci" wx:model="{{customInfo}}" wx:model-prop="info" wx:model-event="change"/>
    <!--动态组件,is传入组件名字符串,可使用的组件需要在json中注册,全局注册也生效-->
    <component is="{{current}}"></component>
    <!--显示/隐藏dom-->
    <view class="bottom" wx:show="{{showBottom}}">
      <!--模板条件编译,__mpx_mode__为框架注入的环境变量,条件判断为false的模板不会生成到dist-->
      <view wx:if="{{__mpx_mode__ === 'wx'}}">wx env</view>
      <view wx:if="{{__mpx_mode__ === 'ali'}}">ali env</view>
    </view>
  </view>
</template>

<script>
  import { createPage } from '@mpxjs/core'

  createPage({
    data: {
      // 动态样式和类名也可以使用computed返回
      dynamicStyle: {
        fontSize: '16px',
        color: 'red'
      },
      title: 'hello world',
      list: [
        {
          content: '全军出击',
          id: 0,
          active: false
        },
        {
          content: '猥琐发育,别浪',
          id: 1,
          active: false
        }
      ],
      customInfo: {
        title: 'test',
        content: 'test content'
      },
      current: 'com-a',
      showBottom: false
    },
    computed: {
      reversedTitle () {
        return this.title.split('').reverse().join('')
      }
    },
    watch: {
      title: {
        handler (val, oldVal) {
          console.log(val, oldVal)
        },
        immediate: true
      }
    },
    handleTap (index) {
      // 处理函数直接通过参数获取当前点击的index,清晰简洁.
      this.list[index].active = !this.list[index].active
    },
    onReady () {
      setTimeout(() => {
        // 更新数据,同时关联的计算属性reversedTitle也会更新
        this.title = '你好,世界'
        // 此时动态组件会从com-a切换为com-b
        this.current = 'com-b'
      }, 1000)
    }
  })
</script>

<script type="application/json">
  {
    "usingComponents": {
      "custom-input": "../components/custom-input",
      "com-a": "../components/com-a",
      "com-b": "../components/com-b"
    }
  }
</script>

<style lang="stylus">
  .container
    position absolute
    width 100%
</style>

更多示例请查看官方示例项目

设计思路

Mpx的核心设计思路为增强,不同于业内大部分小程序框架将web MVVM框架迁移到小程序中运行的做法,Mpx以小程序原生的语法和技术能力为基础,借鉴参考了主流的web技术设计对其进行了扩展与增强,并在此技术上实现了以微信增强语法为base的同构跨平台输出,该设计带来的好处如下:

  • 良好的开发体验:在方便使用框架提供的便捷特性的同时,也能享受到媲美原生开发的确定性和稳定性,完全没有框架太多坑,不如用原生的顾虑;不管是增强输出还是跨平台输出,最终的dist代码可读性极强,便于调试排查;
  • 极致的性能:得益于增强的设计思路,Mpx框架在运行时不需要做太多封装抹平转换的工作,框架的运行时部分极为轻量简洁,压缩+gzip后仅占用14KB;配合编译构建进行的包体积优化和基于模板渲染函数进行的数据依赖跟踪,Mpx框架在性能方面做到了业内最优(小程序框架运行时性能评测报告);
  • 完整的原生兼容:同样得益于增强的设计思路,Mpx框架能够完整地兼容小程序原生技术规范,并且做到实时跟进。在Mpx项目中开发者可以方便地使用业内已有的小程序生态,如组件库、统计工具等;原生开发者们可以方便地进行渐进迁移;甚至可以将框架的跨平台编译能力应用在微信的原生小程序组件当中进行跨平台输出。

生态周边

包名 版本 描述
@mpxjs/core npm version mpx运行时核心
@mpxjs/webpack-plugin npm version mpx编译核心
@mpxjs/api-proxy npm version 将各个平台的 api 进行转换,也可以将 api 转为 promise 格式
@mpxjs/store npm version 类vuex store
@mpxjs/pinia npm version mpx pinia store
@mpxjs/fetch npm version mpx网络请求库,处理wx并发请求限制
@mpxjs/unocss-plugin npm version mpx unocss插件,支持使用unocss原子类
@mpxjs/unocss-base npm version mpx unocss预设
@mpxjs/cli npm version mpx脚手架命令行工具
@mpxjs/webview-bridge npm version 为跨小程序平台的H5项目提供通用的webview-bridge
@mpxjs/utils npm version mpx运行时工具库
@mpxjs/babel-plugin-inject-page-events npm version 组合式API页面事件处理插件
@mpxjs/mpx-cube-ui npm version 基于 Mpx 的移动端基础组件库

开发团队

核心团队: hiyuki, Blackgan3, anotherso1a, CommanderXL, yandadaFreedom, wangxiaokou, OnlyProbie, pagnkelly, thuman, theniceangel, dolymood

外部贡献者:sky-admin, pkingwa, httpsxiao, lsycxyj, okxiaoliang4, tangminFE, codepan, zqjimlove, xuehebinglan, zhaoyiming0803, ctxrr, JanssenZhang, heiye9, lj0812, SuperHuangXu, twtylkmrh, NineSwordsMonster

成功案例

微信小程序

滴滴出行 出行广场 滴滴公交 滴滴金融 滴滴外卖 司机招募 小桔加油
滴滴出行 出行广场 滴滴公交 滴滴金融 滴滴外卖 司机招募 小桔加油
彗星英语 番薯借阅 疫查查应用 小桔养车 学而思直播课 小猴启蒙课 科创书店
彗星英语 番薯借阅 疫查查应用 小桔养车 学而思直播课 小猴启蒙课 科创书店
在武院 三股绳Lite 学而思优选课 食享会 青铜安全医生 青铜安全培训 视穹云机械
在武院 三股绳Lite 学而思优选课 食享会 青铜安全医生 青铜安全培训 视穹云机械
店有生意通 花小猪打车 橙心优选 小二押镖 顺鑫官方微商城 嘀嗒出行 汉行通Pro
店有生意通 花小猪打车 橙心优选 小二押镖 顺鑫官方微商城 嘀嗒出行 汉行通Pro
交圈 青桔单车 滴滴顺风车 滴滴代驾 新桔代驾 标贝知音
交圈 青桔单车 滴滴顺风车 滴滴代驾 新桔代驾 标贝知音

其他平台小程序:

滴滴出行(支付宝) 小桔充电(支付宝) 唯品会QQ 口袋证件照(百度) 唯品会(百度) 唯品会(字节)
滴滴出行(支付宝) 小桔充电(支付宝) 唯品会(QQ) 口袋证件照(百度) 唯品会(百度) 唯品会(字节)

更多案例,若你也在使用Mpx框架开发小程序,并想分享给大家,请填在此issue中。

交流

提供 微信群 / QQ群 两种交流方式

添加MPX入群小助手等待受邀入群

微信

扫码进入QQ群

QQ

图片因github网络问题导致不可见的朋友可以点击该链接:https://s.didi.cn/rod

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Mpx是一款致力于提高小程序开发体验的增强型小程序框架 expand collapse
JavaScript and 6 more languages
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/didiopensource/mpx.git
git@gitee.com:didiopensource/mpx.git
didiopensource
mpx
mpx
master

Search