remax icon indicating copy to clipboard operation
remax copied to clipboard

feat: 自动识别并打包自定义微信小程序组件

Open xiaohutongxue2 opened this issue 4 years ago • 6 comments

简单介绍

remax会将我们的页面直接打成小程序的page,每次数据更新导致setData时都是页面级别的diff和渲染。 如果页面节点较多或者频繁UI更新时可能出现卡顿和响应慢的情况。但是,remax官方仅支持使用原生小程序,不支持直接使用React编写原生小程序。对此我们做了一些改造,通过配置的方式将一些React编写的组件自动打包成微信的组件。

使用说明

需要在app.config.js中配置nativeComponents目录(和pages配置规则相同)。

const nativeComponents = [
  'comp/todoList/index'
];

向组件中传递数据:由于小程序需要定义传入组件的类型(微信自定义组件),所以框架内部只暴露了data传递渲染数据。非渲染数据以及一些function可以使用redux、mobx的方式直接注入组件

<TodoList data={Object} />

改造说明

在remax打包基础上,区分出需要打包成component的逻辑。利用webpack-virtual-modules将component打包成带有特定后缀产物。自定义component的识别基本复用了原生component识别逻辑。区别在于原生的component有现成的产物,自定义component只是指向了component打包产物的路径。

欢迎联系

阅读remax的源码做的改动,可能有些地方疏忽了,有问题可以随时发邮件或者其他方式和我联系 电话:15600696795 邮箱:[email protected]

xiaohutongxue2 avatar Aug 30 '20 09:08 xiaohutongxue2

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/remaxjs/remax/9ggrqoh35
✅ Preview: https://remax-git-fork-xiaohutongxue2-master.remaxjs.vercel.app

vercel[bot] avatar Aug 30 '20 09:08 vercel[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0bdbe97a8ed2d6bb9658cf1a165f30b4aa013b6b:

Sandbox Source
remaxjs/examples: one Configuration

codesandbox-ci[bot] avatar Aug 30 '20 09:08 codesandbox-ci[bot]

赞!

有可能做成一个插件吗

Darmody avatar Aug 31 '20 01:08 Darmody

赞!

有可能做成一个插件吗

不改变remax源码 感觉不太好搞

xiaohutongxue2 avatar Aug 31 '20 06:08 xiaohutongxue2

尝试扩展一下我们的插件能力,做到可以在插件里完成这个功能比较好

Darmody avatar Sep 11 '20 02:09 Darmody

求支持

juvham avatar Dec 07 '20 12:12 juvham