Giter Club home page Giter Club logo

mpx's Introduction

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/cli npm version mpx脚手架命令行工具
@mpxjs/webview-bridge npm version 为跨小程序平台的H5项目提供通用的webview-bridge
@mpxjs/mock npm version 结合mockjs提供数据mock能力
@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

mpx's People

Contributors

1240318070 avatar amorcy avatar anniechan0116 avatar anotherso1a avatar blackgan3 avatar commanderxl avatar ctxrr avatar cuiyinghh avatar cwyyue avatar dependabot[bot] avatar gloomykevin avatar handsomebingo avatar hiyuki avatar httpsxiao avatar kimi233 avatar lsycxyj avatar mater1996 avatar okxiaoliang4 avatar onlyprobie avatar pagnkelly avatar pkingwa avatar qiushuibai avatar sky-admin avatar wangxiaokou avatar wuxianqiang avatar xsyi avatar xuehebinglan avatar yandadafreedom avatar zhaoyiming0803 avatar zhuzhh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpx's Issues

wx:model 双向绑定是不支持自定义组件吗?

我使用的是vant-weapp组件

<van-field
  id="phone"
  wx:model="{{ form.phone }}"
  label="手机号"
  placeholder="请输入手机号"
  error-message="手机号格式错误"
  border="{{ false }}"
/>

测试了一下,双向绑定不起作用,是我那里用得不对吗?

run watch 会出现问题

building...{ Error: ENOTEMPTY: directory not empty, rmdir 'D:\Office\project\wxck\dist\pages'
errno: -4051,
code: 'ENOTEMPTY',
syscall: 'rmdir',
path: 'D:\Office\project\wxck\dist\pages' }
| building...

这个问题必现,最新版本的

mpx 版本
"@mpxjs/core": "^1.0.26",
"@mpxjs/fetch": "^1.0.14",
"@mpxjs/promisify": "^1.0.14",
"@mpxjs/url-loader": "^1.0.15",
"@mpxjs/webpack-plugin": "^1.0.26",

ext.json和project.config.json能打包进dist吗

ext.json和project.config.json能打包进dist吗
虽然 ext.json需要生成小程序包的时候手动写入,但是在测试的时候每次npm run watch 都需要把文件复制进去 比较麻烦。

wx:if 中不能使用 WXS 模块的函数

模版

<view
  class="msg-time"
  wx:if="{{index === 0 || !utils.isSameMinute(item.msgTime, list[index - 1].msgTime)}}"
>
</view>

报如下错误

Expressions in wx:if/wx:elif/wx:for can not contain wxs module data.

mpx文件中引入原生组件报错

image
image

无法引入原生小程序组件

jsEnginScriptError Component is not found in path "components/mpx-demo95b0aa24/src/components/test/test" (using by "pages/index");onAppRoute Error: Component is not found in path "components/mpx-demo95b0aa24/src/components/test/test" (using by "pages/index")

外部引入的wxs会报错

在template里面引入

<wxs src="./../tools.wxs" module="tools" />

会报以下错误:

./../tools.wxs not found from ./pages/index/index.wxml

安装@mpxjs/cli失败

MacBook:~ zhanqi$ npm i -g @mpxjs/cli
npm ERR! Unexpected end of JSON input while parsing near '..."^1.0.0","xo":"*"},"d'

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/zhanqi/.npm/_logs/2019-04-17T03_06_58_812Z-debug.log

全局组件引入支持

在 app.mpx

<script type="application/json"> { "pages": [ "pages/index/index" ], "window": { }, "usingComponents": { } } </script>

引入全局组件支持

安装完脚手架,开发运行报错

webpack不是4.0以上吗?

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

  • configuration has an unknown property '1'. These properties are valid:
    object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }
    For typos: please correct them.
    For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
    Loaders should be updated to allow passing options via loader options in module.rules.
    Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
    plugins: [
    new webpack.LoaderOptionsPlugin({
    // test: /.xxx$/, // may apply this only for some modules
    options: {
    1: …
    }
    })
    ]
    at webpack (/Users/chason/Desktop/mpx/node_modules/webpack/lib/webpack.js:31:9)
    at runWebpack (/Users/chason/Desktop/mpx/build/build.js:30:5)
    at err (/Users/chason/Desktop/mpx/build/build.js:58:3)
    at afterGlob (/Users/chason/Desktop/mpx/node_modules/rimraf/rimraf.js:84:14)
    at f (/Users/chason/Desktop/mpx/node_modules/once/once.js:25:25)
    at Glob. (/Users/chason/Desktop/mpx/node_modules/glob/glob.js:151:7)
    at Glob.emit (events.js:182:13)
    at Glob._finish (/Users/chason/Desktop/mpx/node_modules/glob/glob.js:197:8)
    at done (/Users/chason/Desktop/mpx/node_modules/glob/glob.js:182:14)
    at Glob._processReaddir2 (/Users/chason/Desktop/mpx/node_modules/glob/glob.js:408:12)
    at /Users/chason/Desktop/mpx/node_modules/glob/glob.js:371:17
    at RES (/Users/chason/Desktop/mpx/node_modules/inflight/inflight.js:31:16)
    at f (/Users/chason/Desktop/mpx/node_modules/once/once.js:25:25)
    at Glob._readdirEntries (/Users/chason/Desktop/mpx/node_modules/glob/glob.js:578:10)
    at /Users/chason/Desktop/mpx/node_modules/glob/glob.js:555:12
    at FSReqWrap.oncomplete (fs.js:141:20)

sass-resources-loader没有效果

配置如下:

{
        test: /\.scss$/,
        use: [
          {loader: 'css-loader', options: {sourceMap: true}},
          {loader: 'sass-loader', options: {sourceMap: true}},
          {
            loader: 'sass-resources-loader',
            options: {
              sourceMap: true,
              resources: [
                resolve('src/styles/mixins.scss')
              ]
            }
          }
        ]
      }

在.mpx文件中和.scss文件中均无法找到mixins.scss文件中定义的function
求问这个是哪里配置错误了么?

npm安装第三方组件项目,引用时候无法识别部分es6扩展运算符语法

npm安装第三方组件项目,引用时候无法识别部分es6扩展运算符语法,

以wux-weapp为例:
在index.mpx中引入
{ "navigationBarTitleText": "首页, "usingComponents": { "wux-filterbar": "../components/dist/filterbar" } }

在webpack.base.config.js中配置babel,在谷歌搜的解决办法

{ test: /\.js$/, loader: 'babel-loader', include: [ resolve('src'), resolve('test'), resolve('node_modules/@mpxjs'), resolve('node_modules/wux-weapp') ], options: { presets: ['env', 'es2015', 'react', 'stage-3'] } }

编译提示

./src/components/dist/checkbox-group/index.js (./node_modules/babel-loader/lib!./src/components/dist/checkbox-group/index.js)
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: E:/vueTest/5/demo-test/src/components/dist/checkbox-group/index.js: Unexpected token (46:42)

44 | },
45 | emitEvent(item) {
46 | this.triggerEvent('change', { ...item, name: this.data.name })
| ^
47 | },
48 | },
49 | })
@ ./src/components/dist/checkbox-group/index.js (./node_modules/@mpxjs/webpack-plugin/lib/native-loader.js!./src/components/dist/checkbox-group/index.js) 5:0-41 5:0-41

拷到src下面引入使用,正常编译无报错

希望增加alias支持

  {
    "usingComponents": {
      "list": "../components/list",
      "xx-button": "../../node_modules/xx-weapp/button/index"
    }
  }

如此引入非常不方便

px->rpx转换时的比例

建议在px转换rpx时在已有的基础上将数值*2

以iPhone6的375px为标准尺寸的宽的话,在转换成以750为宽的自适应单位rpx时,若数值不变直接转换单位,显示出的尺寸会很小。

mixins在传递对象数组时长度异常

版本:@mpxjs/core": "^1.1.0 "@mpxjs/webpack-plugin": "^1.1.0"
操作系统:windows10
浏览器:谷歌74.0.3702.0
问题描述:组件使用mixins引入时,定义在mixin.js中的数组对象,长度异常,原来写了3个对象,传递过去后数组对象的长度变为1000,其中前3个位正常数据,后面997个全部为undefined

// mixins.js代码
image

// component代码
image

异常结果:
image

控制台警告信息:
image

用cli生成的项目中,list组件未生成.json文件

用cli生成的项目在运行时报错
VM650:2 未找到 plugin.json 中的定义的 publicComponents "components/list491edbce/list" 对应的 JSON 文件
稍微追了一下,webpack-plugin/lib/json-compiler 文件25行
const rootName = this._compilation._preparedEntrypoints[0].name
来判断是否为app文件并不准确,导致在113行上判断
if (resourcePath === rootName)
时rootName与resourcePath相等了,同为组件名,从而未生成组件的json文件。
具体是哪次做了shift操作?还是组件进入队列的优先级变高了没往下追
是只有我才有的问题吗?
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.