All Projects → yisar → Fard2

yisar / Fard2

Licence: mit
🎅 fre 转小程序的新思路 ♂ learn once, write anywhere.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Fard2

Vscode Miniapp Helper
微信小程序开发助手 for VSCode
Stars: ✭ 137 (+33.01%)
Mutual labels:  wxml, miniapp
miniapp
使用 Rax 语法(类 React)编写跨多端的小程序应用。
Stars: ✭ 65 (-36.89%)
Mutual labels:  mini-program, miniapp
wxml-transpiler
Port of wcc.exe to JavaScript. wxml 文件编译器 --- 里面有很多无用代码,有空再整理下
Stars: ✭ 21 (-79.61%)
Mutual labels:  wxml, miniapp
Qiniu Wxapp Sdk
qiniu SDK based on wxapp
Stars: ✭ 638 (+519.42%)
Mutual labels:  miniapp
Wxopenclub Wxapp Lessons
60 节微信小程序开发视频教程配套源代码
Stars: ✭ 798 (+674.76%)
Mutual labels:  miniapp
Neteasemusicwxminiapp
仿网易云音乐APP的微信小程序
Stars: ✭ 1,092 (+960.19%)
Mutual labels:  miniapp
Xf wx
微信小程序+ 讯飞语音 实现个人语音助手
Stars: ✭ 79 (-23.3%)
Mutual labels:  mini-program
Wxpage
WXPage 是一个极其轻量的微信小程序开发框架,其中的API蕴含了“极致页面打开速度的思想”,为可维护性与开发效率而设计的功能,框架来自“腾讯视频”小程序的项目沉淀,框架对于小程序工程理念为不依赖额外构建,即引即用。腾讯视频播放器插件 =>
Stars: ✭ 589 (+471.84%)
Mutual labels:  miniapp
Tina
💃 一款轻巧的渐进式微信小程序框架
Stars: ✭ 1,153 (+1019.42%)
Mutual labels:  wxml
Mpvue Loader
mpvue loader
Stars: ✭ 47 (-54.37%)
Mutual labels:  wxml
Weather
一个天气查询服务:爬取数据、Web服务、小程序展示
Stars: ✭ 46 (-55.34%)
Mutual labels:  mini-program
Thorui
ThorUI组件库,微信小程序项目代码分享,组件文档地址:https://www.thorui.cn/doc 。 最近更新时间:2021-01-19
Stars: ✭ 817 (+693.2%)
Mutual labels:  wxml
Wepy Calendar
微信小程序/wepy/日历组件
Stars: ✭ 58 (-43.69%)
Mutual labels:  wxml
Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+639.81%)
Mutual labels:  miniapp
Wemark
微信小程序Markdown渲染库
Stars: ✭ 1,159 (+1025.24%)
Mutual labels:  wxml
Calendar
微信小程序日历插件
Stars: ✭ 631 (+512.62%)
Mutual labels:  miniapp
Holy Reader
holy reader!小说阅读器小程序, API源自追书神器
Stars: ✭ 59 (-42.72%)
Mutual labels:  mini-program
Wxapp
这是一个Sublime的插件, 用来开发<微信小程序>.
Stars: ✭ 42 (-59.22%)
Mutual labels:  mini-program
Create Wxapp Page
创建微信小程序页面的命令行工具
Stars: ✭ 37 (-64.08%)
Mutual labels:  mini-program
Autocomplete Wx
一款atom插件,支持微信语法高亮和代码补全
Stars: ✭ 47 (-54.37%)
Mutual labels:  wxml

fard logo

fard NPM version NPM downloads QQ

⛄️ fre 转小程序的新思路 ♂ learn once, write anywhere.

工作日只处理 issue,节假日迭代~

Package Version About
Fard npm fard core
fard-webpack-plugin npm webpack plugin

Usage

import { useState } from 'fre'
import { h, render } from 'fard'
import './index.styl'

function App() {
  const [count, setCount] = useState(0)
  return (
    <view>
      <text>{count}</text>
      <button onClick={() => setCount(count + 1)}>+</button>
    </view>
  )
}

render(<App />)

以上,由于小程序不支持 babel 和 stylus,所以仍然需要借助 webpack

完整的 demo 用例在这里:webpack-demo

hooks

所有 fre 的 hooks API 都是支持的

hooks 相关行为都发生在 fre 层,和小程序无关,不做赘述,请移步:fre readme

api & context

fard 提供 api 对象,用来抹平各个端的差异

import { h, render, api, context } from 'fard'

function App() {
  const toJack = () => {
    api.navigateTo({
      url: '../user/user?name=jack',
    })
    console.log(context)
  }
  return (
    <view>
      <button onClick={toJack}>+</button>
    </view>
  )
}

render(<App />)

如上,api 等同于 wx、my、tt、swan,会根据环境自行更换命名空间

context 是 this 实例

setup

有时候,我们需要自定义一些方法,比如生命周期,和小程序的默认事件

此时需要用到 render 的第二个参数

const setup = {
  onReady() {
    //生命周期
    console.log('onReady……')
  },
  onShareAppMessage(res) {
    //微信自带的方法
    return {
      title: '转发',
      path: '/pages/index/index',
      success(res) {
        console.log('成功', res)
      },
    }
  },
}

render(<App />, setup)

注意,只有根组件和原生组件拥有生命周期,而内置的 fre 组件,请使用 useEffect

fard-webpack-plugin

借助 webpack,还可以顺便做一些构建的工作,如 生成 template bridge复制小程序的配置文件

fard-webpack-plugin 是 fard 唯一一个额外的插件,用来包办 webpack 相关

const FardWebpackPlugin = require('fard-webpack-plugin')

plugins: [
  new FardWebpackPlugin(),
]

template bridge

经过 fard-webpack-plugin 声称的 bridge.wxml 是用来桥接的文件,无需关注其内容

我们只需要在我们每个 page 的 wxml 引用它即可:

<fard vdom="{{vdom}}">

写死的,不用修改

原理

fard 之所以称之为新思路,是因为它不同于其他编译型框架,它的原理和 RN 类似,是比较好的跨端方案

如图:

它通过 bridge 来桥接 fre 和小程序的 vdom,是在小程序里跑 fre 而不是将 fre 编译成小程序

另外,fard 还在 setData 之前做了一层 diff/防抖/压缩 三连,性能靠谱

这里有一篇详细的文章:fard:fre 转小程序的新思路

How to contribute

Since fard use monorepo managed by lerna you should install lerna at first.

npm i -g lerna

Then install all dependencies:

lerna bootstrap

For example run these commands if you'd like to run fard-demo with Webpack:

cd packages/demo-webpack
yarn start

Contributors

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].