Giter Club home page Giter Club logo

miniapp's Introduction

Rax

Rax 小程序是基于运行时驱动的完整跨端小程序开发体系。


🚗 完整的 Rax DSL: 使用完整的 Rax(React) DSL 以及状态管理相关能力,没有任何语法约束

兼容 W3C 标准: 支持标准 DOM 和 BOM API,像开发 Web 应用一样快速开发小程序

🚀 支持双引擎混用: 在小程序项目中,支持局部组件使用编译时方案构建,提供更极致的性能体验

📤 多端支持: 完整支持阿里(支付宝、淘宝、钉钉等)、微信、字节跳动、百度、快手小程序

🍄 跨端组件: 通过 Fusion Mobile 提供跨多小程序的丰富的组件体系

跨端 API: 通过 Uni API 提供跨多小程序的统一 API

快速开始

$ npm init rax rax-miniapp-example # 选择小程序跨端应用的类型
$ cd rax-miniapp-example
$ npm install
$ npm start

然后使用小程序 IDE 即可开始调试:

文档

点击 Rax 官网 查看使用文档

示例

点击 查看 Examples

上线项目案例

如果你也在使用 Rax 开发小程序,欢迎补充到 案例收集 的 issue 中。

微信小程序

盒马集市 优酷视频 全球精品免税城 阿里巴巴零售通
恒安会员+ 雅高酒店集团 零哇智能 淘鲜达优选团长端

点击查看更多使用 Rax 的微信小程序

支付宝小程序

浙里办 电影演出 浙大一院总部一期 游戏充值
盒马集市 飞猪周边游 阿里健康大药房 CUBA我的主场

点击查看更多使用 Rax 的支付宝小程序

淘宝小程序

点击查看使用 Rax 的淘宝小程序

更新日志

点击查看 CHANGELOG

社区

答疑钉钉群 GitHub issues
GitHub issues

贡献代码

请首先阅读 Rax 贡献代码指南,了解基础的规范。

开发配置

运行以下命令:

$ git clone [email protected]:raxjs/miniapp.git
$ cd miniapp
$ npm install
$ npm run setup

调试代码包

以调试 rax-miniapp-runtime-webpack-plugin 为例:

# 进入示例项目
$ cd examples/app-lifecycle
$ npm install
$ npm link ../../packages/rax-miniapp-runtime-webpack-plugin # 本地 link 要调试的代码包
$ npm start # 启动项目,打开小程序 IDE 进行调试

代码包组成

NPM 包 描述
miniapp-render Rax 小程序运行时方案模拟 DOM/BOM API
miniapp-runtime-config Rax 小程序运行时方案工程公共配置
miniapp-history Rax 小程序模拟 history
rax-miniapp-babel-plugins Rax 小程序代码扫描 babel 插件
rax-miniapp-config-webpack-plugin Rax 小程序配置生成 Webpack 插件
rax-miniapp-runtime-webpack-plugin Rax 小程序运行时方案模板代码生成 Webpack插件
driver-miniapp Rax 小程序运行时方案 driver(什么是 driver
jsx-compiler Rax 小程序编译时方案核心编译器
jsx2mp-cli Rax 小程序编译时方案命令行启动工具(废弃)
jsx2mp-loader Rax 小程序编译时方案 Webpack loader
jsx2mp-runtime Rax 小程序编译时方案运行时垫片
miniapp-builder-shared Rax 小程序公用方法及变量等
miniapp-compile-config Rax 小程序编译时方案工程公共配置

协议

BSD License

miniapp's People

Contributors

chriscindy avatar cryzzchen avatar dickeylth avatar felaofan avatar myhirra avatar shiftj18 avatar solojiang avatar wanglijie 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

Watchers

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

miniapp's Issues

[Enhance]优化Babel重复注入helper函数问题

关联issue

解决方案

build.json中增加字段envOptions, 用于修改此处@babel/preset-env插件的参数
简单实现:

build.json
{
  "envOptions": {
    "targets": {
      "chrome": "90"
    }
  }
}
output.js
[[require('@babel/preset-env'), {
      exclude: ['@babel/plugin-transform-regenerator'],
      ...envOptions
}]]

原因说明

关键目的在于抽离Babel的helper函数。而这个功能目前微信开发者工具已经具备,可参考微信Bebel转译说明 ,
经过实验发现,无论传给微信开发者工具的代码是否经过es6转译es5,开发者工具都会自动注入完整的helper函数。因此在rax端解决helper函数多次注入问题并不是最优解,原因是这样至少都会有一次的重复注入。合理的做法应该是让开发者通过配置,选择性关闭部分es6转译es5功能,使rax端生成的代码不含helper函数,把转译任务交给开发者工具。

为什么强调选择性关闭?
微信小程序并没有完全兼容es6+语法,因此对部分较新的语法进行转译是有必要的。需要转译到什么程度,开发者可以通过配置envOptions.targets字段值去解决。

目前遇到的问题

新增build.json字段需要修改build-plugin-component这个插件, 不了解修改这个插件代码需要在哪里提pr。

TypeError: Cannot read properties of undefined (reading 'parentPath')

console.log(compile(`export default <div>test</div>`, {...baseOptions}));
C:\Users\HP\IdeaProjects\web-framework\node_modules\jsx-compiler\src\modules\code.js:472
  if (exportComponentPath.parentPath.isExportDefaultDeclaration()) {
                          ^

TypeError: Cannot read properties of undefined (reading 'parentPath')
    at getReplacer (C:\Users\HP\IdeaProjects\web-framework\node_modules\jsx-compiler\src\modules\code.js:472:27)
    at Object.parse (C:\Users\HP\IdeaProjects\web-framework\node_modules\jsx-compiler\src\modules\code.js:83:24)
    at invokeModules (C:\Users\HP\IdeaProjects\web-framework\node_modules\jsx-compiler\src\utils\invokeModules.js:11:25)
    at parse (C:\Users\HP\IdeaProjects\web-framework\node_modules\jsx-compiler\src\parser\index.js:133:3)
    at compile (C:\Users\HP\IdeaProjects\web-framework\node_modules\jsx-compiler\src\index.js:13:18)
    at Object.<anonymous> (C:\Users\HP\IdeaProjects\web-framework\index.js:99:13)
    at Module._compile (node:internal/modules/cjs/loader:1275:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)

Node.js v19.8.1

【支付宝小程序】ScrollView 调用 scrollTo 不生效

【问题描述】
创建 scrollView 后使用 ref 赋值,外部调用 scrollTo 方法没效果。
控制台输出 ref.current 有值。

控制台表现

【期望效果】
可以滑动到指定位置。

【代码】

import { createElement, useRef } from 'rax';
import View from 'rax-view';
import ScrollView from 'rax-scrollview';


export default function Home() {

  const svRef = useRef(null);

  return (
    <View styel={{ width: '100vw', height: '100vw', position: 'relative' }}>
      <ScrollView
        ref={svRef}
        style={{ width: '100vw', height: '100vh' }}
      >
        {
          new Array(100).fill(0).map((value, index) => {
            return (
              <View key={`line-${index}`} style={{ width: '100%', height: '80rpx' }}>
                line-{index}
              </View>
            );
          })
        }
        <View style={{ position: 'absolute', right: 0, bottom: '100rpx', width: '200rpx', height: '80rpx', color: 'white', backgroundColor: 'blue' }} onClick={() => { svRef.current.scrollTo({ x: 0, y: 0 }); }}>
          To Top
        </View>
      </ScrollView>
    </View>
  );
}

【复现 demo仓库】
https://github.com/MarshallYang/rax-miniapp-scrollto-bug

在微信小程序 IDE 中直接开发 Rax 小程序

目前,Rax 小程序项目推荐用户使用 VS Code 等编辑器打开项目,通过终端执行 npm run start/build 将代码编译到产物文件夹(微信端是 build/wechat-miniprogram),然后使用微信 IDE 打开该文件夹进行预览。如果需要直接使用微信 IDE 进行开发,需要按照以下步骤操作:

  1. 新建 Rax 小程序项目,并通过微信 IDE 打开;
  2. 在项目根目录下新建 project.config.json (可能微信 IDE 在打开项目后会自动创建),在其中添加以下内容用于指定小程序目录:
{
  "miniprogramRoot": "build/wechat-miniprogram"
}
  1. 打开终端进入项目根目录(系统自带或者微信 IDE 中新建终端),安装依赖并启动代码编译:
$ npm install
$ npm run start
  1. 用户可编辑 src 目录下的源码进行开发,同时可实时在 IDE 中预览小程序。

双引擎融合方案实现

GOAL: 支持在单一运行时项目中灵活配置使用编译时组件
USAGE: 用户在 src/miniapp-compiled 文件夹中放置且被使用到的组件全部使用编译时引擎编译
TODO:

  • babel 插件扫描,将 miniapp-compiled 文件夹内的组件识别为原生自定义组件
  • 接入编译时组件工程,编译 miniapp-compiled 文件夹内使用到的组件
  • 工程体验优化,自动进入产物文件夹进行 npm install
  • 编译时组件引入方式可以按照正常书写习惯,无需按照 usingComponents 的方式书写完整路径
  • babel 插件在每次文件变化编译时均重新扫描输出 props 和 events
  • miniapp-render 文件处理逻辑优化,支持直接安装依赖以覆盖默认配置

🌟 案例收集

欢迎大家把使用 Rax 开发上线的小程序项目,更新到此 issue 下,格式是:小程序名称 + 平台(微信 or 支付宝 or 手淘 or ...) + 介绍(可选) + 二维码 + 链接(可选)

[Feature]小程序状态管理

目前 Rax 小程序使用了 @ice/store 作为状态管理方案,对于全局状态而言存在一些问题:
在小程序中,打开一个页面在处理上更接近 MPA 的新建页面,即需要渲染整个页面。@ice/store 依赖了 react-redux,并将 Provider 放在页面组件的父亲节点上。这样会导致 Provider 节点会被重新创建,如果用户在 src/app.ts 中声明了全局的初始状态,那么新打开的页面会被重新初始化一次,导致全局状态管理失效。
解决方案:
初步想法是将状态挂在到 App 或 Page 上,用小程序的全局和页面属性来保存状态。这套方案在对外接口上保持与 @ice/store 保持一致。

百度、快手小程序 flex 布局失效

目前使用 Rax 小程序运行时方案开发百度、快手小程序时, flex 布局在会失效,例如:

<View style={{display: 'flex'}}>
  <View>1</View>
  <View>2</View>
</View>

原因在于Rax 运行时小程序方案使用 template 递归渲染节点,而 template 在百度、快手小程序是真实 DOM 节点,则上述结构渲染出的真实结构伪代码如下:

<template>
  <view style={{display: 'flex'}}>
    <template>
      <view>1</view>
    </template>
    <template>
      <view>2</view>
    </template>
  </view>
</template>

导致 flex 布局失效。因此,需要更新百度、快手侧的 view 等常用 flex 布局的组件的 template 模板,原理大致如 taro 社区用户讨论:NervJS/taro#6015 (comment)

createAnimation中的参数不起作用

设置 createAnimation 中的参数例如 duration: 100,实际情况不起作用。

具体代码:

实际 console.log 的输出

期望:
能正确赋值

[Bug] 支付宝小程序通过 getSearchParams 取到的值有问题

跳转代码已对 url 做 encode

import navigate from 'universal-navigate'

navigate.push( {
  url: '/pages/webview/index?url=' + encodeURIComponent( url )
} )

在另一个页面获取 searchParams

import { getSearchParams } from 'rax-app'

return () => {
  const searchParams = getSearchParams();
  // 这里的 searchParams 存在问题
}

假如传入的 url 是 "https://a.com?foo=1&bar=2"

在支付宝小程序中获取到的 searchParams 为

{
  "url": "https://a.com?foo=1",
  "bar": 2
}

正确的值应该为

{
  "url": "https://a.com?foo=1&bar=2",
}

在微信小程序中没有问题

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.