or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api-interceptors.mdconfig-compilation.mdevent-system.mdframework-runtime.mdindex.mdmp-runtime.mdutility-functions.mdwxs-utilities.md
tile.json

config-compilation.mddocs/

Configuration and Compilation

Build-time configuration and template compilation utilities for WeChat Mini Program development. These tools handle platform-specific build settings, file extensions, and component generation during the development and build process.

Capabilities

Platform Configuration

WeChat Mini Program specific build configuration including CSS variables, file extensions, and feature flags.

interface WeXinConfig {
  /** Platform-specific configuration options */
  options: {
    /** CSS custom properties for status bars and window areas */
    cssVars: {
      '--status-bar-height': string;
      '--window-top': string;
      '--window-bottom': string;
      '--window-left': string;
      '--window-right': string;
    };
    /** File extension mappings for WeChat Mini Program */
    extnames: {
      style: string;   // '.wxss'
      template: string; // '.wxml'
      filter: string;  // '.wxs'
    };
    /** Template filter tag name */
    filterTag: string; // 'wxs'
    /** Project configuration file name */
    project: string; // 'project.config.json'
    /** Subpackage support flag */
    subPackages: boolean; // true
    /** Dark mode support flag */
    darkmode: boolean; // true
  };
  /** Generate webpack copy configuration */
  copyWebpackOptions(platformOptions: any, vueOptions: any): CopyOption[];
}

Configuration Example:

// Default WeChat Mini Program configuration
const weixinConfig = {
  options: {
    cssVars: {
      '--status-bar-height': '25px',
      '--window-top': '0px',
      '--window-bottom': '0px',
      '--window-left': '0px',
      '--window-right': '0px'
    },
    extnames: {
      style: '.wxss',
      template: '.wxml',
      filter: '.wxs'
    },
    filterTag: 'wxs',
    project: 'project.config.json',
    subPackages: true,
    darkmode: true
  }
};

Webpack Copy Configuration

Generate copy configuration for webpack build process including theme files, sitemap, and custom components.

/**
 * Generate copy configuration for webpack build process
 * @param platformOptions - Platform-specific build options
 * @param vueOptions - Vue.js build options
 * @returns Array of copy configuration objects for webpack
 */
function copyWebpackOptions(platformOptions: any, vueOptions: any): CopyOption[];

Usage in Build Process:

// Build configuration example
const copyOptions = weixinConfig.copyWebpackOptions(
  { workers: 'workers' }, // Platform options
  {} // Vue options
);

// Result includes:
// - theme.json (theme configuration)
// - sitemap.json (search indexing configuration)
// - ext.json (extension configuration)
// - custom-tab-bar (custom tab bar components)
// - plugin.json (plugin configuration)
// - wxcomponents (WeChat native components)
// - uni_modules components

Template Compilation

Advanced template compilation features for scoped slots and component generation.

/**
 * Create scoped slot components for WeChat Mini Program
 * @param slotName - Name of the scoped slot
 * @param props - Component properties
 * @param state - Compilation state object
 * @returns Array of component definitions
 */
function createScopedSlots(slotName: string, props: any, state: CompilerState): ComponentDefinition[];

/**
 * Resolve scoped slots into WeChat Mini Program components
 * @param slotName - Name of the slot to resolve
 * @param context - Compilation context with code generation utilities
 * @param state - Compilation state object
 * @returns Empty string (generates files as side effect)
 */
function resolveScopedSlots(
  slotName: string, 
  context: CompilerContext, 
  state: CompilerState
): string;

Code Generation

Utilities for generating WeChat Mini Program component code during build process.

/**
 * Generate JavaScript code for WeChat Mini Program components
 * @param properties - Component properties definition (defaults to '{}')
 * @returns Generated JavaScript code string
 */
function generateJsCode(properties?: string): string;

/**
 * Generate CSS import code for component styles
 * @param filename - CSS file name to import
 * @returns CSS import statement
 */
function generateCssCode(filename: string): string;

Code Generation Examples:

// Generate component JavaScript
const jsCode = generateJsCode(`{
  "text": {
    "type": "String",
    "default": "Hello"
  },
  "size": {
    "type": "Number", 
    "default": 14
  }
}`);

// Result:
// wx.createComponent({
//   generic: true,
//   props: { "text": { "type": "String", "default": "Hello" }, ... },
//   render: function(){}
// })

// Generate CSS import
const cssCode = generateCssCode('button.wxss');
// Result: @import "./button.wxss"

Build Integration

Webpack Configuration

Integration with webpack build process:

// webpack.config.js example
const weixinConfig = require('@dcloudio/uni-mp-weixin/lib/uni.config.js');

module.exports = {
  // ... other config
  plugins: [
    new CopyWebpackPlugin(
      weixinConfig.copyWebpackOptions(
        platformOptions,
        vueOptions
      )
    )
  ]
};

Component Compilation

Automatic compilation of Vue components to WeChat Mini Program format:

// Build process integration
const compiler = require('@dcloudio/uni-mp-weixin/lib/uni.compiler.js');

// During build, Vue single-file components are processed
// and converted using the compiler utilities:
// - Template compilation with scoped slots
// - Style processing with WeChat-specific extensions
// - Script transformation for WeChat Mini Program runtime

Project Structure

The configuration supports standard WeChat Mini Program project structure:

project/
├── app.js                 // Application entry
├── app.json              // Application configuration
├── app.wxss              // Global styles
├── project.config.json   // Project configuration
├── sitemap.json          // Search configuration
├── theme.json            // Theme configuration
├── pages/                // Page components
│   └── index/
│       ├── index.js
│       ├── index.json
│       ├── index.wxml
│       └── index.wxss
├── components/           // Custom components
├── wxcomponents/         // Native WeChat components
└── uni_modules/          // Uni-app modules

Environment Variables

Configuration can be customized through environment variables:

// Environment-based configuration
const config = {
  options: {
    cssVars: {
      '--status-bar-height': process.env.STATUS_BAR_HEIGHT || '25px',
      '--window-top': process.env.WINDOW_TOP || '0px'
    }
  }
};

WeChat Developer Tools Integration

Automator configuration for integration with WeChat Developer Tools, enabling automated testing and debugging capabilities.

/**
 * WeChat Developer Tools configuration for automation and testing
 */
interface WeChatAutomatorConfig {
  /** Developer tools information */
  devtools: {
    /** Tool name for identification */
    name: string;
    /** Remote debugging capability flag */
    remote: boolean;
    /** Automation support flag */
    automator: boolean;
    /** Default installation paths by platform */
    paths: string[];
    /** Required project files for automation */
    required: string[];
    /** Default WebSocket port for communication */
    defaultPort: number;
  };
  /** Automation protocol adapters */
  adapter: {
    /** Remote debugging enablement */
    "Tool.enableRemoteDebug": AutomatorAdapter;
    /** Function call execution */
    "App.callFunction": AutomatorAdapter;
    /** HTML content retrieval */
    "Element.getHTML": AutomatorAdapter;
  };
}

interface AutomatorAdapter {
  /** Adapter reflection function for protocol communication */
  reflect: (executor: Function, params: any) => Promise<any>;
}

Automator Usage Example:

// WeChat Developer Tools automation setup
const automatorConfig = {
  devtools: {
    name: "Wechat web devTools",
    remote: true,
    automator: true,
    paths: [
      // Windows path
      "C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat",
      // macOS path  
      "/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
    ],
    required: ["project.config.json", "app.json", "app.js"],
    defaultPort: 9420
  }
};

// Runtime automation initialization
wx.$$initRuntimeAutomator({
  success() {
    console.log('自动化测试已启动');
  },
  fail(error) {
    console.error('自动化测试启动失败:', error);
  }
});

Automation Capabilities:

  • Remote Debugging: Connect to WeChat Developer Tools remotely for debugging
  • Page Automation: Automate page interactions, data retrieval, and method calls
  • Component Testing: Test individual components and their behaviors
  • Mock API: Mock uni-app API methods for testing scenarios
  • QR Code Handling: Automatic QR code reading and processing for testing
  • WebSocket Communication: Real-time communication with developer tools

Types

// Copy configuration for webpack
interface CopyOption {
  from: string;
  to: string;
  ignore?: string[];
}

// Compiler state for template processing
interface CompilerState {
  componentGenerics?: Record<string, boolean>;
  scopedSlots?: Record<string, number>;
  files?: Record<string, string>;
  generic?: string[];
  errors?: {
    add(message: string): void;
  };
  options?: {
    platform?: {
      name: string;
    };
  };
}

// Compiler context for code generation
interface CompilerContext {
  genCode: (node: any, optimize?: boolean) => string;
  generate: (nodes: any[], state: CompilerState) => string;
  ownerName: string;
  parentName: string;
  parentNode: any;
  resourcePath: string;
  paramExprNode: any;
  returnExprNodes: any[];
  traverseExpr: (nodes: any[], state: CompilerState) => any[];
}

// Component definition for generated components
interface ComponentDefinition {
  type: string;
  attr: Record<string, any>;
  children: any[];
}

// Platform build options
interface PlatformOptions {
  workers?: string;
  [key: string]: any;
}

// Vue build options
interface VueOptions {
  [key: string]: any;
}

// Automator types (already defined above in API blocks)
// WeChatAutomatorConfig and AutomatorAdapter interfaces