On this page

Adapt to Platforms

Homogeneous files

You can write the programming logic by using different file extensions in your project to adapt to a specific platform.

  • .tsx universally used
  • .web.tsx web application
  • .mini.tsx miniApp
    • .wechat.tsx WeChat MiniApp
    • .tuya.tsx Smart MiniApp

You can use the --target parameter in the command-line interface (CLI) to specify the platform for which your miniapp will be built and debugged. Then, the project files will be loaded sequentially from bottom to top in the preceding structure.

Runtime

Differentiate environment variables by runtime.

import {
  isWeb,
  isWechat,
  isTuya,
  isMiniProgram,
  isIOS,
  isAndroid,
  isNative,
} from '@ray-js/env';

Example:

import { isTuya, isWechat } from '@ray-js/env';

export function say() {
  if (isTuya) {
    // Logic of Smart MiniApp
  } else if (isWechat) {
    // Logic of WeChat MiniApp
  } else {
    //
  }
}