Taro platform plugin for compiling applications to TouTiao (ByteDance) mini program platform
npx @tessl/cli install tessl/npm-tarojs--plugin-platform-tt@4.1.0The @tarojs/plugin-platform-tt is a Taro platform plugin that enables compilation and deployment of Taro applications to TouTiao (ByteDance) mini program platform. This plugin provides platform-specific APIs, components, build configurations, and runtime support necessary for TouTiao mini program development.
npm install @tarojs/plugin-platform-ttimport ttPlatformPlugin from "@tarojs/plugin-platform-tt";
import { TT } from "@tarojs/plugin-platform-tt";For CommonJS:
const ttPlatformPlugin = require("@tarojs/plugin-platform-tt");
const { TT } = require("@tarojs/plugin-platform-tt");Runtime utilities and components:
import {
initNativeApi,
needPromiseApis,
components,
hostConfig
} from "@tarojs/plugin-platform-tt/dist/runtime-utils";import type { IPluginContext } from '@tarojs/service';
import ttPlatformPlugin from '@tarojs/plugin-platform-tt';
// In a Taro config file
export default {
plugins: [
// Register the TouTiao platform plugin
ttPlatformPlugin
]
};
// The plugin will automatically register the 'tt' platform
// when Taro builds with --type ttThe plugin is built around several key components:
The main plugin function that registers TouTiao platform support with Taro.
/**
* Main plugin function that registers TouTiao platform support
* @param ctx - Taro plugin context providing platform registration capabilities
*/
export default (ctx: IPluginContext) => {
ctx.registerPlatform({
name: 'tt',
useConfigName: 'mini',
async fn ({ config }) {
// Handles external pages and app configuration
// Creates and starts TT platform instance
}
});
};Platform implementation class that can be extended by other platform plugins.
/**
* TouTiao platform implementation class extending TaroPlatformBase
*/
export class TT extends TaroPlatformBase {
platform: 'tt';
globalObject: 'tt';
projectConfigJson: 'project.tt.json';
runtimePath: string;
taroComponentsPath: string;
fileType: {
templ: '.ttml';
style: '.ttss';
config: '.json';
script: '.js';
xs: '.sjs';
};
template: Template;
constructor(ctx: any, config: any);
modifyTemplate(): void;
}Template compilation system for TouTiao mini program templates.
/**
* Template engine for TouTiao mini program template compilation
*/
export class Template extends RecursiveTemplate {
supportXS: true;
Adapter: {
if: 'tt:if';
else: 'tt:else';
elseif: 'tt:elif';
for: 'tt:for';
forItem: 'tt:for-item';
forIndex: 'tt:for-index';
key: 'tt:key';
xs: 'sjs';
type: 'tt';
};
replacePropName(name: string, value: string): string;
buildXsTemplate(filePath?: string): string;
}Functions for adapting Taro APIs to work with TouTiao platform.
/**
* Transforms API calls for TouTiao platform compatibility
* @param api - API name to transform
* @param options - API options to modify
* @returns Transformed API configuration
*/
export function transformMeta(
api: string,
options: Record<string, any>
): { key: string; options: Record<string, any> };
/**
* Initializes native TouTiao APIs in Taro runtime
* @param taro - Taro instance to enhance with TouTiao APIs
*/
export function initNativeApi(taro: any): void;Pre-configured component settings for TouTiao platform compatibility.
/**
* Component configuration object for TouTiao-specific components
*/
export const components: {
// Standard components with TouTiao-specific attributes
Icon: { size: '24' };
Input: {
'adjust-position': '!0';
'hold-keyboard': '!1';
'clue-type': '0';
bindKeyboardHeightChange: '';
};
Button: {
bindGetPhoneNumber: '';
'data-channel': '';
'data-aweme-id': '';
'group-id': '';
'data-is-half-page': '';
bindOpenAwemeUserProfile: '';
bindJoinGroup: '';
};
Form: {
'report-submit-timeout': '0';
};
Slider: {
color: "'#e9e9e9'";
'selected-color': "'#1aad19'";
};
WebView: {
'progressbar-color': "'#51a0d8'";
};
Video: {
'play-btn-position': "'center'";
'pre-roll-unit-id': '';
'post-roll-unit-id': '';
'vslide-gesture': '!1';
'vslide-gesture-in-fullscreen': '!0';
'enable-play-gesture': '!1';
'show-playback-rate-btn': '!1';
'enable-play-in-background': '!1';
signature: '';
bindProgress: '';
bindSeekComplete: '';
bindAdLoad: '';
bindAdStart: '';
bindAdEnded: '';
bindAdError: '';
bindAdClose: '';
bindLoadedMetadata: '';
bindPlaybackRateChange: '';
bindMuteChange: '';
bindControlTap: '';
bindEnterBackground: '';
bindCloseBackground: '';
bindLeaveBackground: '';
};
Ad: {
fixed: '';
type: "'banner'";
scale: '100';
};
Textarea: {
'disable-default-padding': '!1';
'confirm-type': "'return'";
'confirm-hold': '!1';
'show-confirm-bar': '!0';
'adjust-position': '!0';
'hold-keyboard': '!1';
};
ScrollView: {
enhanced: '!1';
bounces: '!0';
'refresher-enabled': '!1';
'refresher-threshold': '55';
'refresher-default-style': "'black'";
'refresher-background': "'#FFF'";
'refresher-triggered': '!1';
bindRefresherPulling: '';
bindRefresherRefresh: '';
bindRefresherRestore: '';
bindRefresherAbort: '';
};
Canvas: {
type: '';
};
Map: {
polygons: '[]';
rotate: '0';
skew: '0';
'max-scale': '19';
'min-scale': '3';
'enable-3D': '!1';
'show-compass': '!1';
'show-scale': '!1';
'enable-overlooking': '!1';
'enable-zoom': '!0';
'enable-scroll': '!0';
'enable-rotate': '!1';
'enable-satellite': '!1';
'enable-traffic': '!1';
'enable-poi': '!0';
'enable-building': '!0';
bindLabelTap: '';
bindRegionChange: '';
bindAnchorPointTap: '';
};
// TouTiao-specific components
RtcRoom: {
'user-id': '';
mode: 'camera';
'device-position': 'front';
bindError: '';
};
PayButton: {
mode: '1';
'goods-id': '';
'goods-type': '';
'order-status': '0';
'order-id': '';
'refund-id': '';
'refund-total-amount': '';
'biz-line': '1';
'marketing-ready': '!1';
bindGetGoodsInfo: '';
bindPlaceOrder: '';
bindError: '';
bindApplyRefund: '';
bindRefund: '';
bindPay: '';
};
ConsumeCard: {
'order-id': '';
bindConsume: '';
bindRefund: '';
bindApplyRefund: '';
bindError: '';
};
AwemeData: {
'aweme-id': '';
type: "'avatar'";
'disable-default': '';
'default-avatar': '';
'default-text': '';
bindError: '';
};
RateButton: {
'order-id': '';
bindInit: '';
bindSuccess: '';
bindError: '';
};
OpenData: {
type: '';
'default-text': '';
'default-avatar': '';
'use-empty-value': '!1';
bindError: '';
};
AwemeUserCard: {
'aweme-id': '';
width: '504';
height: '144';
fixed: '!1';
'left-right-padding': '';
bindError: '';
};
};Set of TouTiao APIs that require Promise wrapping for asynchronous operations.
/**
* Set of API names that need Promise wrapping for TouTiao platform
*/
export const needPromiseApis: Set<string>;The set includes these TouTiao-specific APIs:
applyRefund - Apply for refund operationscanRateAwemeOrders - Check if orders can be ratedcheckFollowAwemeState - Check follow state for Aweme userscheckFollowState - Check general follow statecontinueToPay - Continue payment processcreateOrder - Create new ordersexitMiniProgram - Exit mini programfollowAwemeUser - Follow Aweme usersfollowOfficialAccount - Follow official accountsgetMenuButtonLayout - Get menu button layout informationgetUserProfile - Get user profile datahideInteractionBar - Hide interaction barnavigateToVideoView - Navigate to video viewopenAwemeUserProfile - Open Aweme user profilesopenEcGood - Open e-commerce goodsopenWebcastRoom - Open webcast roomspay - Process paymentsrateAwemeOrder - Rate Aweme ordersshowDouyinOpenAuth - Show Douyin authorizationshowInteractionBar - Show interaction barTouTiao-specific React components for use in Taro applications.
/**
* Re-exports all standard Taro mini program components
*/
export * from '@tarojs/components/mini';
/**
* TouTiao-specific React components
*/
export const RtcRoom: 'rtc-room';
export const PayButton: 'pay-button';
export const ConsumeCard: 'consume-card';
export const AwemeData: 'aweme-data';
export const RateButton: 'rate-button';
export const OpenData: 'open-data';
export const AwemeUserCard: 'aweme-user-card';Runtime host configuration for TouTiao platform integration.
/**
* Runtime host configuration for TouTiao platform
*/
export const hostConfig: {
initNativeApi: (taro: any) => void;
modifyMpEventImpl: (event: any) => void;
modifyTaroEventReturn: (node: any, event: any, returnVal: any) => any;
};The hostConfig object provides:
initNativeApi: Initializes TouTiao native APIs in the Taro runtimemodifyMpEventImpl: Modifies events, specifically transforming regionchange events to use event.detail.typemodifyTaroEventReturn: Handles special return value processing for pay-button component events (applyrefund and getgoodsinfo)TypeScript type extensions for Taro APIs with TouTiao-specific properties.
declare module '@tarojs/taro' {
namespace getSystemInfoSync {
interface Result {
/** Host APP name for TouTiao platform */
appName?: string;
}
}
namespace getSystemInfo {
interface Result {
/** Host APP name for TouTiao platform */
appName?: string;
}
}
}The plugin automatically handles external pages (pages with ext:// prefix) by:
modifyAppConfigmodifyBuildAssetsThis allows TouTiao mini programs to reference external pages hosted by the platform while maintaining proper build configuration.
The plugin handles several error scenarios:
.ttml files for TouTiao template markup.ttss files for TouTiao-specific styling.sjs files for TouTiao Script (similar to WXS).json files for component and page configurationproject.tt.json for TouTiao-specific project settingstt objectregionchange events to use event.detail.typepay-button component eventsbindlongtap → bindlongpress)