Convert Figma logo to code with AI

Tencent logokbone

一个致力于微信小程序和 Web 端同构的解决方案

4,776
454
4,776
21

Top Related Projects

4,776

一个致力于微信小程序和 Web 端同构的解决方案

39,886

A cross-platform framework using Vue.js

35,461

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/

4,569

使用真正的 React 构建跨平台小程序

🦎 一套代码运行多端,一端所见即多端所见

1,328

:dancer: 一款轻巧的渐进式微信小程序框架

Quick Overview

Kbone is a framework for building cross-platform applications that can run on both the web and WeChat mini-programs. It provides a unified API and development experience, allowing developers to create applications that can seamlessly run on multiple platforms.

Pros

  • Cross-Platform Compatibility: Kbone enables developers to create applications that can run on both the web and WeChat mini-programs, reducing the need for separate codebases.
  • Unified Development Experience: Kbone provides a consistent API and development workflow, making it easier for developers to build and maintain their applications.
  • Performance Optimization: Kbone is designed to optimize performance by leveraging platform-specific features and optimizations.
  • Extensive Documentation: The Kbone project has comprehensive documentation, including guides, tutorials, and API references, making it easier for developers to get started and learn the framework.

Cons

  • Limited to WeChat Mini-Programs: Kbone is primarily focused on supporting WeChat mini-programs, which may limit its usefulness for developers who need to target other platforms.
  • Steep Learning Curve: Developers who are new to Kbone may face a steeper learning curve, as they need to understand the framework's unique concepts and development workflow.
  • Potential Vendor Lock-in: By using Kbone, developers may become more dependent on the WeChat ecosystem, which could lead to vendor lock-in concerns.
  • Ongoing Maintenance: As a relatively new framework, Kbone may require more ongoing maintenance and updates to keep up with changes in the WeChat mini-program ecosystem.

Code Examples

Example 1: Creating a Simple Page

import { render, h } from 'kbone';

const App = () => (
  <div>
    <h1>Hello, Kbone!</h1>
    <p>This is a simple Kbone application.</p>
  </div>
);

render(<App />, document.getElementById('app'));

This code demonstrates how to create a simple page using Kbone's render and h functions.

Example 2: Handling User Interactions

import { render, h, useState } from 'kbone';

const Counter = () => {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>Click me</button>
    </div>
  );
};

render(<Counter />, document.getElementById('app'));

This example shows how to handle user interactions and manage state using Kbone's useState hook.

Example 3: Accessing Platform-Specific APIs

import { render, h, useEffect } from 'kbone';
import { getSystemInfo } from 'kbone/api';

const SystemInfo = () => {
  const [systemInfo, setSystemInfo] = useState(null);

  useEffect(() => {
    const fetchSystemInfo = async () => {
      const info = await getSystemInfo();
      setSystemInfo(info);
    };
    fetchSystemInfo();
  }, []);

  return (
    <div>
      {systemInfo ? (
        <p>
          Device Model: {systemInfo.model}
          <br />
          System Version: {systemInfo.system}
        </p>
      ) : (
        <p>Loading system information...</p>
      )}
    </div>
  );
};

render(<SystemInfo />, document.getElementById('app'));

This code demonstrates how to access platform-specific APIs, such as the getSystemInfo function, using Kbone.

Getting Started

To get started with Kbone, follow these steps:

  1. Install the Kbone CLI:
npm install -g kbone-cli
  1. Create a new Kbone project:
kbone-cli create my-app
  1. Navigate to the project directory and install dependencies:
cd my-app
npm install
  1. Start the development server:
npm run dev

This will start the development server and open your application in the browser. You can also run the application in a WeChat mini-program environment by following the instructions

Competitor Comparisons

4,776

一个致力于微信小程序和 Web 端同构的解决方案

Pros of kbone

  • Comprehensive cross-platform development framework
  • Supports multiple mini-program platforms
  • Extensive documentation and community support

Cons of kbone

  • Steeper learning curve for beginners
  • May have more overhead for simpler projects
  • Requires additional configuration for complex scenarios

Code Comparison

kbone example:

import { h, render } from 'vue'
import App from './App.vue'

render(h(App), document.getElementById('app'))

kbone example:

import { h, render } from 'vue'
import App from './App.vue'

render(h(App), document.getElementById('app'))

As both repositories are the same (Tencent/kbone), there are no actual differences in the code or features to compare. The code examples provided are identical, demonstrating a basic Vue.js application setup using kbone.

kbone is a powerful framework for developing cross-platform applications, particularly for WeChat mini-programs and web applications. It offers a unified development experience, allowing developers to write code once and deploy it across multiple platforms. While it may have a steeper learning curve, its extensive features and community support make it a valuable tool for complex, multi-platform projects.

39,886

A cross-platform framework using Vue.js

Pros of uni-app

  • Supports a wider range of platforms, including iOS, Android, Web, and various mini-program ecosystems
  • Offers a more comprehensive development framework with built-in UI components and APIs
  • Provides a unified development experience across multiple platforms

Cons of uni-app

  • Steeper learning curve due to its proprietary syntax and framework-specific concepts
  • May have limitations when accessing platform-specific features or implementing complex custom UI

Code Comparison

uni-app:

<template>
  <view>
    <text>{{ message }}</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      message: 'Hello, uni-app!'
    }
  }
}
</script>

kbone:

import { h, createApp } from 'vue'

const app = createApp({
  render() {
    return h('div', [h('span', 'Hello, kbone!')])
  }
})

app.mount('#app')

Key Differences

  • uni-app uses a Vue-like single-file component structure, while kbone relies on standard web development practices
  • uni-app provides a more abstracted approach to cross-platform development, whereas kbone focuses on web-to-miniprogram conversion
  • kbone offers more flexibility for existing web projects, while uni-app is better suited for new cross-platform applications
35,461

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/

Pros of Taro

  • Supports multiple platforms (Web, WeChat Mini Program, Alipay Mini Program, etc.)
  • Large and active community with extensive documentation
  • Provides a unified development experience across platforms

Cons of Taro

  • Steeper learning curve due to its comprehensive nature
  • May have performance overhead in some scenarios
  • Limited access to platform-specific APIs without custom components

Code Comparison

Taro (React-like syntax):

import { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'

export default class Index extends Component {
  render() {
    return (
      <View>
        <Text>Hello, World!</Text>
      </View>
    )
  }
}

Kbone (Vue syntax):

<template>
  <div>
    <p>Hello, World!</p>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld'
}
</script>

Key Differences

  • Taro uses a React-like syntax, while Kbone supports Vue
  • Taro focuses on cross-platform development, Kbone emphasizes Web-to-WeChat Mini Program conversion
  • Taro has a more opinionated structure, Kbone offers more flexibility in project setup

Use Cases

  • Choose Taro for multi-platform projects with a preference for React-like syntax
  • Opt for Kbone when converting existing Vue web apps to WeChat Mini Programs
4,569

使用真正的 React 构建跨平台小程序

Pros of Remax

  • Simpler API and more intuitive development experience for React developers
  • Better TypeScript support and type inference
  • More flexible and customizable build process

Cons of Remax

  • Smaller community and ecosystem compared to Kbone
  • Limited to React framework, while Kbone supports multiple frameworks
  • Less comprehensive documentation and examples

Code Comparison

Remax example:

import React from 'react';
import { View, Text } from 'remax/wechat';

export default () => (
  <View>
    <Text>Hello, Remax!</Text>
  </View>
);

Kbone example:

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

ReactDOM.render(<App />, document.getElementById('app'))

Both Remax and Kbone aim to simplify cross-platform development for mini-programs, but they take different approaches. Remax focuses on providing a React-like development experience specifically for mini-programs, while Kbone offers a more general solution for adapting web applications to mini-program environments.

Remax provides a more straightforward development experience for React developers, with better TypeScript support and a more flexible build process. However, it has a smaller community and ecosystem compared to Kbone, and is limited to the React framework.

Kbone, on the other hand, supports multiple frameworks and has a larger community, but may have a steeper learning curve and less intuitive API for React developers.

🦎 一套代码运行多端,一端所见即多端所见

Pros of Chameleon

  • Supports a wider range of platforms, including web, WeChat Mini Program, Alipay Mini Program, Baidu Smart Program, and native apps
  • Provides a more comprehensive framework for cross-platform development, including routing and state management
  • Offers a unified API layer for consistent development across platforms

Cons of Chameleon

  • Steeper learning curve due to its custom DSL and framework-specific concepts
  • Less focus on web-to-WeChat Mini Program conversion, which is Kbone's primary strength
  • Smaller community and ecosystem compared to Kbone

Code Comparison

Chameleon component example:

<template>
  <view>
    <text>{{message}}</text>
  </view>
</template>

<script>
class Index {
  data = {
    message: 'Hello Chameleon'
  }
}
export default new Index();
</script>

Kbone component example:

import { h, createApp } from 'vue'

createApp({
  render() {
    return h('div', [
      h('span', 'Hello Kbone')
    ])
  }
}).mount('#app')

Both Chameleon and Kbone aim to simplify cross-platform development, but they take different approaches. Chameleon offers a more comprehensive framework with its own DSL, while Kbone focuses on enabling web projects to run in WeChat Mini Program environments with minimal changes.

1,328

:dancer: 一款轻巧的渐进式微信小程序框架

Pros of tina

  • Lightweight and focused on WeChat Mini Program development
  • Simpler learning curve for developers familiar with Vue.js
  • Better suited for smaller, less complex projects

Cons of tina

  • Limited cross-platform support compared to kbone's broader capabilities
  • Smaller community and ecosystem compared to kbone's backing by Tencent
  • Less frequent updates and maintenance

Code Comparison

tina example:

Page.define({
  data: {
    message: 'Hello World'
  },
  onLoad() {
    console.log('Page loaded')
  }
})

kbone example:

import { h, createApp } from 'vue'

createApp({
  render() {
    return h('div', 'Hello World')
  }
}).mount('#app')

tina focuses on a more WeChat Mini Program-specific approach, while kbone provides a more versatile framework for cross-platform development. tina's syntax is closer to traditional Mini Program development, whereas kbone leverages Vue.js conventions for a more familiar experience for web developers.

Both frameworks aim to simplify Mini Program development, but they cater to different project scales and developer preferences. tina is more suitable for developers who want a lightweight solution specifically for WeChat Mini Programs, while kbone offers greater flexibility and cross-platform capabilities for larger, more complex projects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

kbone

kbone 是一个致力于微信小程序和 Web 端同构的解决方案。

简介

微信小程序的底层模型和 Web 端不同,我们想直接把 Web 端的代码挪到小程序环境内执行是不可能的。kbone 的诞生就是为了解决这个问题,它实现了一个适配器,在适配层里模拟出了浏览器环境,让 Web 端的代码可以不做什么改动便可运行在小程序里。

这里有个简单的代码片段:https://developers.weixin.qq.com/s/R9Hm0Qm67Acd,可以使用开发者工具打开看看效果。

因为 kbone 是通过提供适配器的方式来实现同构,所以它的优势很明显:

  • 大部分流行的前端框架都能够在 kbone 上运行,比如 Vue、React、Preact 等。
  • 支持更为完整的前端框架特性,因为 kbone 不会对框架底层进行删改(比如 Vue 中的 v-html 指令、Vue-router 插件)。
  • 提供了常用的 dom/bom 接口,让用户代码无需做太大改动便可从 Web 端迁移到小程序端。
  • 在小程序端运行时,仍然可以使用小程序本身的特性(比如像 live-player 内置组件、分包功能)。
  • 提供了一些 Dom 扩展接口,让一些无法完美兼容到小程序端的接口也有替代使用方案(比如 getComputedStyle 接口)。

使用

为了可以让开发者可以更自由地进行项目的搭建,以下提供了三种方式,任选其一即可:

使用 kbone-cli 快速开发

对于新项目,可以使用 kbone-cli 来创建项目,首先安装 kbone-cli:

npm install -g kbone-cli

创建项目:

kbone init my-app

进入项目,按照 README.md 的指引进行开发:

// 开发小程序端
npm run mp

// 开发 Web 端
npm run web

// 构建 Web 端
npm run build

PS:项目基于 webpack 构建,关于 webpack 方面的配置可以点此查看,而关于小程序构建相关的详细配置细节可以参考此文档。

使用模板快速开发

除了使用 kbone-cli 外,也可以直接将现有模板 clone 下来,然后在模板基础上进行开发改造:

项目 clone 下来后,按照项目中 README.md 的指引进行开发。

手动配置开发

此方案基于 webpack 构建实现,如果你不想要使用官方提供的模板,想要更灵活地搭建自己的项目,又或者是想对已有的项目进行改造,则需要自己补充对应配置来实现 kbone 项目的构建。

一般需要补充两个配置:

点此可以查看具体配置方式和操作流程。

kbone-ui

kbone-ui 是一个能同时支持 小程序(kbone) 和 vue 框架开发的多端 UI 库。

  • 即可以基于 kbone 同时开发小程序和 H5,也可以单独使用开发 H5 应用。
  • 支持以 Vue 语法来支持 H5 端和小程序端运行
  • 对齐 微信weui 样式组件

文档

更为详细的说明和指引,可点击查看文档。

PS:如果文档无法访问,可尝试访问备份文档镜像。

问题

此方案虽然将整个 Web 端框架包含进来并提供了适配层,但是也不是银弹,无法满足所有场景,具体限制可参考问题文档。如果还遇到其他问题,可在 issue 中反馈。

选择

业内其实已经出现了很多关于同构的解决方案了,每个方案都有自己的优劣,不存在能够完美解决所有问题的方案。kbone 也一样,它的优势在上面提到过,而它的不足也是它的实现原理带来的。kbone 是使用一定的性能损耗来换取更为全面的 Web 端特性支持。

所以关于性能方面,如果你对小程序的性能特别苛刻,建议直接使用原生小程序开发;如果你的页面节点数量特别多(通常在 1000 节点以上),同时还要保证在节点数无限上涨时仍然有稳定的渲染性能的话,可以尝试一下业内采用静态模板转译的方案;其他情况就可以直接采用 kbone 了。

贡献者

感谢你们

查看代码贡献规范。

交流

QQ 交流群:926335938

使用相关问题可在 Kbone社区 发帖

案例

微信开放社区

License

MIT

NPM DownloadsLast 30 Days