All Projects → skyFi → Weapp Native

skyFi / Weapp Native

weapp-native (wn) 像React组件开发一样来开发微信小程序,开发微信小程序框架 [此项目短时间内已不再维护,有兴趣继续的可以加群联系我]

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Weapp Native

Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+8339.58%)
Mutual labels:  weapp, jsx
Virtual Dom
关于Vue,React,Preact和Omi等框架源码的解读
Stars: ✭ 139 (-3.47%)
Mutual labels:  jsx
Tua Mp
🖖一款类 Vue 的渐进式小程序框架(A progressive miniprogram framework for coding like Vue)
Stars: ✭ 127 (-11.81%)
Mutual labels:  weapp
Fetop100
微信小程序 “前端TOP100”
Stars: ✭ 135 (-6.25%)
Mutual labels:  weapp
Preact And Typescript
Some simple patterns for Typescript usage with Preact
Stars: ✭ 127 (-11.81%)
Mutual labels:  jsx
Dependency Cruiser
Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
Stars: ✭ 2,326 (+1515.28%)
Mutual labels:  jsx
Ink Gradient
Gradient color component for Ink
Stars: ✭ 123 (-14.58%)
Mutual labels:  jsx
Raven Weapp
Sentry SDK for WeApp
Stars: ✭ 142 (-1.39%)
Mutual labels:  weapp
React Code Blocks
React code blocks and code snippet components
Stars: ✭ 135 (-6.25%)
Mutual labels:  jsx
Mdx
Markdown for the component era
Stars: ✭ 11,948 (+8197.22%)
Mutual labels:  jsx
Ink Link
Link component for Ink
Stars: ✭ 133 (-7.64%)
Mutual labels:  jsx
Old
每天大红包 · 旧版(不再维护,仅供参考)
Stars: ✭ 1,611 (+1018.75%)
Mutual labels:  weapp
Redux React Starter
DEPRECATED use the new https://github.com/didierfranc/react-webpack-4
Stars: ✭ 137 (-4.86%)
Mutual labels:  jsx
Jstoxml
JavaScript object to XML converter (useful for RSS, podcasts, GPX, AMP, etc)
Stars: ✭ 127 (-11.81%)
Mutual labels:  jsx
X0
Document & develop React components without breaking a sweat
Stars: ✭ 1,706 (+1084.72%)
Mutual labels:  jsx
Wxdraw
A lightweight canvas library which providing 2d draw for weapp 微信小程序2d动画库 😎 🐼
Stars: ✭ 1,625 (+1028.47%)
Mutual labels:  weapp
Storybook Addon Playroom
Design with Playroom inside Storybook, using each story source as a starting point
Stars: ✭ 133 (-7.64%)
Mutual labels:  jsx
Preact Minimal
🚀 Minimal preact structure
Stars: ✭ 136 (-5.56%)
Mutual labels:  jsx
Yundocs
云档3.0版本,taro开发。可打包多平台小程序,h5,IOS和Android客户端。欢迎star跟进
Stars: ✭ 143 (-0.69%)
Mutual labels:  weapp
Omil
📝Webpack loader for Omi.js React.js and Rax.js components 基于 Omi.js,React.js 和 Rax.js 单文件组件的webpack模块加载器
Stars: ✭ 140 (-2.78%)
Mutual labels:  jsx

wn-cli

暂不维护,推荐一个 https://github.com/NervJS/taro

wn-cli 像React组件开发一样来开发微信小程序

名字由来:wn -> weapp native 取第一个字母

Install

npm install wn-cli --save-dev
// 或者
yarn add wn-cli --dev

Usage

// 构建
npx wn ./examples ./dist

// 监听模式
npx wn ./examples ./dist -w

如果你遇到一个错误,让拷贝 wn.js 文件,请按提示信息将 node_modules 中的 node_modules/wn-cli/dist/wn.js 文件拷贝到 modules 文件夹中

你的目录可能是这样的:

├── dist
│   ├── app.js
│   ├── app.json
│   ├── app.wxss
│   ├── modules
│   │   └── wn.js
│   ├── pages
│   │   ├── index
│   │   │   ├── index.js
│   │   │   ├── index.json
│   │   │   └── index.wxml
│   │   │   └── index.wxss
│   │   └── me
│   │       ├── me.js
│   │       ├── me.json
│   │       └── me.wxml
│   │       └── me.wxss
│   └── project.config.json
├── package.json
├── project.config.json
├── src
│   ├── app.jsx
│   ├── app.css
│   └── pages
│       ├── index
│       │   ├── index.css
│       │   └── index.jsx
│       └── me
│       │   ├── me.css
│           └── me.jsx
└── yarn.lock

然后在微信开发者工具中打开 dist/ 文件夹,就可以预览开发了,可以选择你喜欢的编辑器。

将来集成的功能

  • this 代理 wx, getApp等
  • 优化原生请求 request,避免请求限制
  • 接入 redux
  • 接入 saga
  • 增加 gulp 管理工作流
  • 增加 less 预编译
  • 扩展 { } 操作符

API

注册小程序

创建 app.jsx 文件,这也是小程序的入口文件,可能像下面这样写

// src/app.jsx
import { App } from 'wn';
// 引入所有的页面,相对路径
import './pages/index/index.jsx';
import './pages/me/me.jsx';

export default class extends App {
  debug = true

  window = {
    navigationBarTitleText: 'hello',
    navigationBarTextStyle: 'black',
    navigationBarBackgroundColor: '#f4f5f6',
    backgroundColor: '#f4f5f6',
  }

  tabBar = {
    color: '#333333',
    backgroundColor: '#ffffff',
    list: [
      {
        pagePath: 'pages/index/index', // 编译后js路径
        text: '首页',
      },
      {
        pagePath: 'pages/me/me',
        text: '我',
      },
    ],
  }

  myData = '自定义公共变量'

  hello() { return '自定义公共函数' }

  // 生命周期函数
  onLaunch() { console.log('app: hello onLaunch') }
  onShow() { console.log('app: hello onShow') }
  onHide() { console.log('app: hello onHide') }
  onError() { console.log('app: hello onError') }
}

同样的,可以通过在 app.js 同目录下创建 app.css ,来书写公用的 css

/* src/app.css */
.test {
  color: red;
}

如此,小程序就注册好了。

创建页面

创建第一个页面,在 src/pages 下面创建页面文件,如 index/index.jsx,可以这样写:

// src/pages/index/index.jsx
import { Page, wx } from 'wn'

export default class extends Page {
  window = {
    navigationBarTitleText: 'hello'
  }
  navigationBarTextStyle = 'black'

  async onShow() {
    const systemInfo = await wx.getSystemInfo()
    console.log('系统信息', systemInfo);
  }

  data = {
    name: '小程序'
  }

  render() {
    return (
      <view class="test">
        你好,{name}      
      </view>
    )
  }
}

添加文件作用域的样式文件,相当于css module,在 src/pages/index 文件夹下面创建同名 css 文件 index.css,不用再导入,只需要命名和同文件下的 .jsx 文件相同就可以了

/* src/pages/index/index.css */
.test {
  color: blue;
  text-align: center;
}

如此第一个页面就创建好了,接下来你可以添加自己的 me.jsx 页面。

创建组件

创建第一个组件,如 header,在 src/components下面创建 header/header.jsxheader/header.css,两文件

// src/components/header/header.jsx
import { Component } from 'wn'

export default class extends Component {
  render() {
    return (
      <view class="header">
        <slot></slot>  
      </view>
    )
  }
}

  • slot 表示组件的 children 放置的位置,还可以指定位置,设置 slotname
/* src/components/header/header.css */
.header {
  color: blue;
}

使用组件

创建了组件后,在页面中使用,首先在页面中导入:

import header from '../../components/header/header.jsx';

然后在需要的时候使用:

render() {
    return (
      <view class="test">
        <header>
          hello
        </header>
        你好,{name}      
      </view>
    )
  }

也可以组件嵌套等。

Promise 化微信 API,即使用 Promise 代理 wx 中的异步方法

如:

// ...
async onShow() {
    const systemInfo = await wx.getSystemInfo()
    console.log(systemInfo);
  }
// ...
  • 注:原生 API 配置中的 complete 方法并没有代理

以上

  • 暂时的功能能满足大多数简单的微信小程序开发,后续在使用中遇到瓶颈了,再配置兼容性开发高级 API 满足需求。

  • 最后的目的是能满足所有(99%)微信小程序开发者的需求,全面(99%)覆盖小程序开发。像 React Native 开发 APP 一样,用wn-cli 开发 weapp (微信小程序)

  • 离目标还有不小的距离,如果你也是 React 派,对微信小程序有兴趣,可以 fork 代码共同建设维护这个工程 ,或许比较懒,那就直接提 ISSUE,这两样都会使我开心一整天的,当然,你的star也会令我开心好久。

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].