Command-line interface tool for Taro, a cross-platform framework that enables developers to build apps for Mini Programs, Web, and mobile platforms
npx @tessl/cli install tessl/npm-tarojs--cli@4.1.0Taro CLI is the command-line interface tool for Taro, an open-source cross-platform framework that enables developers to build applications for Mini Programs, Web, and mobile platforms. The CLI provides comprehensive commands for project creation, development, building, and deployment across multiple platforms including WeChat Mini Programs, Baidu Smart Program, Alipay Mini Program, and more.
npm install -g @tarojs/cliimport { CLI, Creator, Project, defineConfig, doctor, getRootPath } from "@tarojs/cli";For CommonJS:
const { CLI, Creator, Project, defineConfig, doctor, getRootPath } = require("@tarojs/cli");import { CLI } from "@tarojs/cli";
// Initialize and run CLI
const cli = new CLI();
cli.run();
// Or use in custom Node.js scripts
import { Project, defineConfig } from "@tarojs/cli";
// Define Taro configuration
const config = defineConfig({
projectName: 'my-app',
framework: 'react',
compiler: 'webpack5',
// ... other config
});Command Line Usage:
# Initialize new project
taro init my-project
# Build for specific platform
taro build --type weapp
# Start development server
taro build --type h5 --watch
# Create new page
taro create
# Run project diagnostics
taro doctorTaro CLI is built around several key components:
Main CLI class that handles command parsing, environment setup, and command execution for all Taro operations.
class CLI {
constructor(appPath?: string);
run(): Promise<void>;
parseArgs(): Promise<void>;
}Comprehensive project scaffolding system with support for multiple frameworks, templates, and customization options.
class Project extends Creator {
constructor(options: IProjectConf);
init(): Promise<void>;
create(): Promise<void>;
}
interface IProjectConf {
projectName: string;
projectDir: string;
npm: NpmType;
templateSource: string;
framework: FrameworkType;
typescript?: boolean;
css: CSSType;
template: string;
description?: string;
autoInstall?: boolean;
}Utilities for creating pages and components within existing Taro projects, with automatic configuration updates.
interface IPageConf {
projectDir: string;
projectName: string;
pageName: string;
framework: FrameworkType;
css: CSSType;
typescript?: boolean;
pageDir?: string;
subPkg?: string;
}
function modifyPagesOrSubPackages(
configPath: string,
pagePath: string,
subPackage?: string
): ConfigModificationState;Plugin creation and management system for extending Taro functionality with custom build processes and platform support.
class Plugin extends Creator {
constructor(options: IPluginConf);
create(): Promise<void>;
getCliVersion(): string;
}
interface IPluginConf {
pluginName: string;
type: string;
description?: string;
projectDir: string;
projectName: string;
template: string;
version: string;
}Type-safe configuration system with environment-specific overrides and webpack merge capabilities.
function defineConfig<T extends CompilerTypes = CompilerWebpackTypes>(
config: UserConfigExport<T>
): UserConfigExport<T>;
interface ConfigEnv {
command: string;
mode: string;
}
type UserConfigFn<T extends CompilerTypes = CompilerWebpackTypes> = (
merge: WebpackMerge,
env: ConfigEnv
) => IProjectConfig<T> | Promise<IProjectConfig<T>>;
type UserConfigExport<T extends CompilerTypes = CompilerWebpackTypes> =
| IProjectConfig<T>
| Promise<IProjectConfig<T>>
| UserConfigFn<T>;Comprehensive project health checking system that validates environment, configuration, packages, and provides recommendations.
const doctor: {
validators: Array<(args?: any) => Promise<void> | void>;
};Core utility functions for path resolution, package management, file operations, and development helpers.
function getRootPath(): string;
function getPkgVersion(): string;
function getAllFilesInFolder(folder: string, filter?: string[]): Promise<string[]>;
function getTemplateSourceType(url: string): TemplateSourceType;
function printPkgVersion(): void;type FrameworkType = 'react' | 'vue3' | 'preact' | 'solid';
type CompilerTypes = 'webpack5' | 'vite' | 'esbuild';
type CSSType = 'sass' | 'stylus' | 'less' | 'none';
type NpmType = 'npm' | 'yarn' | 'pnpm' | 'cnpm';
type TemplateSourceType = 'git' | 'url';
interface FileStat {
name: string;
isDirectory: boolean;
isFile: boolean;
}
enum ConfigModificationState {
Success = 'SUCCESS',
Fail = 'FAIL'
}
type WebpackMerge = (...configs: Array<object | null | undefined>) => object;