Skip to main content
Version: 3.x

Overview

Platform Plugin#

Since v3.1.0, we have extracted the compatibility logic for each mini program platform and injected it into the Taro framework as a Taro plugin into the Taro framework to support compilation for the corresponding platform.

Taro Includes Platform Plugins#

PluginCompile Platform
@tarojs/plugin-platform-weappWechat Mini Program
@tarojs/plugin-platform-alipayAlipay Mini Program
@tarojs/plugin-platform-swanSwan Smart Program
@tarojs/plugin-platform-ttByteDance Mini Program
@tarojs/plugin-platform-qqQQ Mini Program
@tarojs/plugin-platform-jdJingdong Mini Program

Other Platform Plugin#

PluginCompile Platform
@tarojs/plugin-platform-weapp-qyEnterprise WeChat Mini Program
@tarojs/plugin-platform-alipay-ddDingTalk Mini Program
@tarojs/plugin-platform-alipay-iotAlipay IOT Mini Program

Platform Plugin Usage#

  1. Configuration Plugin
// Taro Project Configuration
module.exports = {
// ...
plugins: [
'@tarojs/plugin-platform-alipay-iot'
]
}
  1. Compile as Alipay IOT Mini Program
taro build --type iot
taro build --type iot --watch

Background#

Open Framework#

In recent years, there are more and more mini program platforms launched, but there are only 6 platforms maintained by Taro core (WeChat, Alipay, Baidu, ByteDance, QQ, Jingdong mini program), so some students often ask if they can support Feature Request of a certain platform.

Based on the current architecture, the compatibility code for a single platform is distributed in various corners of the Taro core library, involving compile-time and run-time parts. Supporting a new platform requires changes to all these places, which makes development complicated and makes it difficult for the community to participate in contributing.

For this reason we came up with the idea of building an open framework. The goal is to extend Taro's end-platform support capabilities in the form of plugins for.

  • Plugin developers can write a platform plugin without modifying the Taro core library code and following certain rules.
  • Plugin users only need to install and configure the end-platform plugin to compile the code to the specified platform.

Platform extensions can be further divided into horizontal and vertical extensions in two ways:

  • Horizontal extensions

    Extend a brand new compiled platform, such as the Meituan mini program.

  • Vertical extension

    Inherit existing platform plugin and extend a new compilation platform, such as QQ mini program plugin inherit from WeChat mini program plugin.

Open compilation platform architecture diagram#

What else is interesting to do#

In addition to extending the new compilation platform, we can also write custom platform plugins that inject custom logic into the platform's compilation process by inheriting from existing platform plugins.

Use the plugin @tarojs/plugin-inject to quickly add APIs, components, adjust component properties, etc. for all mini program mini program

Quick fixes for problems#

Due to the large number of mini program platforms and the fact that they are constantly iterating, there is often an issue where Taro does not have timely support for a newly introduced component or API of an mini program. Developers would first need to contact the Taro team and then wait for us to follow up with a fix and release a new version before they could use it properly, which would take an average of a week or two weeks to be resolved.

Based on the open compilation platform architecture, developers can quickly develop custom platform plugins by inheriting the target platform plugins to complete support for these new components or APIs without waiting for Taro to release a version.

Property Simplification#

Because the properties and events of the mini program components must be written statically and cannot be added dynamically, Taro binds all the properties and events of the components in the template in advance.

However, in many cases, the actual project does not use all the properties and events of the component, and the redundant property and event bindings will occupy a large part of the volume, and too many event bindings will also reduce the performance of the mini program to some extent.

The following is the pseudo code for the View component template.

<template name="tmpl_0_view">
<view
hover-class="..."
hover-stop-propagation="..."
hover-start-time="..."
hover-stay-time="..."
animation="..."
onTouchStart="..."
onTouchMove="..."
onTouchEnd="..."
onTouchCancel="..."
onLongTap="..."
onAnimationStart="..."
onAnimationIteration="..."
onAnimationEnd="..."
onTransitionEnd="..."
disable-scroll="..."
hidden="..."
onAppear="..."
onDisappear="..."
onFirstAppear="..."
style="..."
class="..."
onTap="..."
id="..."
>
...
</view>
</template>

Taro needs to bind all properties and events of the View component in advance in order to meet the needs of different developers. However, for a developer who may not use the hover-stop-propagation property for the entire View component of the project, consider streamlining it and not compiling it into the View template.

Attribute refinement can also be achieved by implementing a custom platform plugin. However, it is important to note that refinement of properties can cause unnecessary problems and make maintenance of the project difficult, and should be designed and used with care, especially when the project is large and has many developers.

Welcome to build together#

We hope that after the launch of the open architecture, we can stimulate the creativity of developers in the community to create new platform support plugins or various excellent custom platform components for the Taro ecosystem, and we look forward to your participation and contribution!