{"id":26926611,"url":"https://github.com/skyfi/weapp-native","last_synced_at":"2025-06-22T13:07:25.336Z","repository":{"id":57398736,"uuid":"117204974","full_name":"skyFi/weapp-native","owner":"skyFi","description":"weapp-native (wn) 像React组件开发一样来开发微信小程序，开发微信小程序框架 [此项目短时间内已不再维护，有兴趣继续的可以加群联系我]","archived":false,"fork":false,"pushed_at":"2018-12-12T01:46:42.000Z","size":114,"stargazers_count":142,"open_issues_count":4,"forks_count":23,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-24T20:41:06.547Z","etag":null,"topics":["jsx","miniprogram","react","weapp","wn-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skyFi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-12T06:53:42.000Z","updated_at":"2024-03-03T14:04:00.000Z","dependencies_parsed_at":"2022-09-01T16:04:25.083Z","dependency_job_id":null,"html_url":"https://github.com/skyFi/weapp-native","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/skyFi/weapp-native","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Fweapp-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Fweapp-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Fweapp-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Fweapp-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyFi","download_url":"https://codeload.github.com/skyFi/weapp-native/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyFi%2Fweapp-native/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261296911,"owners_count":23137218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsx","miniprogram","react","weapp","wn-cli"],"created_at":"2025-04-02T03:34:37.727Z","updated_at":"2025-06-22T13:07:20.327Z","avatar_url":"https://github.com/skyFi.png","language":"JavaScript","readme":"# **wn-cli**\n\n\u003e 暂不维护，推荐一个 https://github.com/NervJS/taro\n\nwn-cli 像React组件开发一样来开发微信小程序\n\n名字由来：**wn -\u003e weapp native** 取第一个字母\n\n# Install\n\n```\nnpm install wn-cli --save-dev\n// 或者\nyarn add wn-cli --dev\n```\n\n# Usage\n\n```\n// 构建\nnpx wn ./examples ./dist\n\n// 监听模式\nnpx wn ./examples ./dist -w\n```\n如果你遇到一个错误，让拷贝 `wn.js` 文件，请按提示信息将 `node_modules` 中的 `node_modules/wn-cli/dist/wn.js` 文件拷贝到 `modules` 文件夹中\n\n你的目录可能是这样的：\n```\n├── dist\n│   ├── app.js\n│   ├── app.json\n│   ├── app.wxss\n│   ├── modules\n│   │   └── wn.js\n│   ├── pages\n│   │   ├── index\n│   │   │   ├── index.js\n│   │   │   ├── index.json\n│   │   │   └── index.wxml\n│   │   │   └── index.wxss\n│   │   └── me\n│   │       ├── me.js\n│   │       ├── me.json\n│   │       └── me.wxml\n│   │       └── me.wxss\n│   └── project.config.json\n├── package.json\n├── project.config.json\n├── src\n│   ├── app.jsx\n│   ├── app.css\n│   └── pages\n│       ├── index\n│       │   ├── index.css\n│       │   └── index.jsx\n│       └── me\n│       │   ├── me.css\n│           └── me.jsx\n└── yarn.lock\n\n```\n然后在微信开发者工具中打开 `dist/` 文件夹，就可以预览开发了，可以选择你喜欢的编辑器。\n\n# 将来集成的功能\n\n* this 代理 wx, getApp等\n* 优化原生请求 request，避免请求限制\n* 接入 redux\n* 接入 saga\n* 增加 gulp 管理工作流\n* 增加 less 预编译\n* 扩展 `{ }` 操作符\n\n# API\n\n## 注册小程序\n\n创建 `app.jsx` 文件，这也是小程序的入口文件，可能像下面这样写\n```JavaScript\n// src/app.jsx\nimport { App } from 'wn';\n// 引入所有的页面，相对路径\nimport './pages/index/index.jsx';\nimport './pages/me/me.jsx';\n\nexport default class extends App {\n  debug = true\n\n  window = {\n    navigationBarTitleText: 'hello',\n    navigationBarTextStyle: 'black',\n    navigationBarBackgroundColor: '#f4f5f6',\n    backgroundColor: '#f4f5f6',\n  }\n\n  tabBar = {\n    color: '#333333',\n    backgroundColor: '#ffffff',\n    list: [\n      {\n        pagePath: 'pages/index/index', // 编译后js路径\n        text: '首页',\n      },\n      {\n        pagePath: 'pages/me/me',\n        text: '我',\n      },\n    ],\n  }\n\n  myData = '自定义公共变量'\n\n  hello() { return '自定义公共函数' }\n\n  // 生命周期函数\n  onLaunch() { console.log('app: hello onLaunch') }\n  onShow() { console.log('app: hello onShow') }\n  onHide() { console.log('app: hello onHide') }\n  onError() { console.log('app: hello onError') }\n}\n\n```\n\n同样的，可以通过在 `app.js` 同目录下创建 `app.css` ，来书写公用的 `css` 。\n```css\n/* src/app.css */\n.test {\n  color: red;\n}\n```\n如此，小程序就注册好了。\n\n## 创建页面\n\n创建第一个页面，在 `src/pages` 下面创建页面文件，如 `index/index.jsx`，可以这样写：\n```javascript\n// src/pages/index/index.jsx\nimport { Page, wx } from 'wn'\n\nexport default class extends Page {\n  window = {\n    navigationBarTitleText: 'hello'\n  }\n  navigationBarTextStyle = 'black'\n\n  async onShow() {\n    const systemInfo = await wx.getSystemInfo()\n    console.log('系统信息', systemInfo);\n  }\n\n  data = {\n    name: '小程序'\n  }\n\n  render() {\n    return (\n      \u003cview class=\"test\"\u003e\n        你好，{name}      \n      \u003c/view\u003e\n    )\n  }\n}\n\n``` \n\n添加文件作用域的样式文件，相当于`css module`，在 `src/pages/index` 文件夹下面创建同名 `css` 文件 `index.css`，不用再导入，只需要命名和同文件下的 `.jsx` 文件相同就可以了\n```css\n/* src/pages/index/index.css */\n.test {\n  color: blue;\n  text-align: center;\n}\n```\n如此第一个页面就创建好了，接下来你可以添加自己的 `me.jsx` 页面。\n\n## 创建组件\n\n创建第一个组件，如 `header`，在 `src/components`下面创建 `header/header.jsx` 和 `header/header.css`，两文件\n``` javascript\n// src/components/header/header.jsx\nimport { Component } from 'wn'\n\nexport default class extends Component {\n  render() {\n    return (\n      \u003cview class=\"header\"\u003e\n        \u003cslot\u003e\u003c/slot\u003e  \n      \u003c/view\u003e\n    )\n  }\n}\n\n```\n\n* `slot` 表示组件的 `children` 放置的位置，还可以指定位置，设置 `slot` 的 `name`。\n\n```css\n/* src/components/header/header.css */\n.header {\n  color: blue;\n}\n```\n\n## 使用组件\n\n创建了组件后，在页面中使用，首先在页面中导入：\n```javascript\nimport header from '../../components/header/header.jsx';\n```\n然后在需要的时候使用：\n```javascript\nrender() {\n    return (\n      \u003cview class=\"test\"\u003e\n        \u003cheader\u003e\n          hello\n        \u003c/header\u003e\n        你好，{name}      \n      \u003c/view\u003e\n    )\n  }\n```\n也可以组件嵌套等。\n\n# Promise 化微信 API，即使用 Promise 代理 wx 中的异步方法\n\n如：\n\n```javascript\n// ...\nasync onShow() {\n    const systemInfo = await wx.getSystemInfo()\n    console.log(systemInfo);\n  }\n// ...\n```\n\n* 注：原生 `API` 配置中的 `complete` 方法并没有代理\n\n# 以上\n\n* 暂时的功能能满足大多数简单的微信小程序开发，后续在使用中遇到瓶颈了，再配置兼容性开发高级 API 满足需求。\n\n* 最后的目的是能满足所有（99%）微信小程序开发者的需求，全面（99%）覆盖小程序开发。像 `React Native` 开发 `APP` 一样，用`wn-cli` 开发 `weapp （微信小程序）`。\n\n* 离目标还有不小的距离，如果你也是 `React` 派，对微信小程序有兴趣，可以 `fork` 代码共同建设维护这个工程 ，或许比较懒，那就直接提 [`ISSUE`](https://github.com/skyFi/weapp-native/issues/new)，这两样都会使我开心一整天的，当然，你的`star`也会令我开心好久。\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyfi%2Fweapp-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyfi%2Fweapp-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyfi%2Fweapp-native/lists"}