or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-tarojs--cli

Command-line interface tool for Taro, a cross-platform framework that enables developers to build apps for Mini Programs, Web, and mobile platforms

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@tarojs/cli@4.1.x

To install, run

npx @tessl/cli install tessl/npm-tarojs--cli@4.1.0

0

# Taro CLI

1

2

Taro 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.

3

4

## Package Information

5

6

- **Package Name**: @tarojs/cli

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `npm install -g @tarojs/cli`

10

11

## Core Imports

12

13

```typescript

14

import { CLI, Creator, Project, defineConfig, doctor, getRootPath } from "@tarojs/cli";

15

```

16

17

For CommonJS:

18

19

```javascript

20

const { CLI, Creator, Project, defineConfig, doctor, getRootPath } = require("@tarojs/cli");

21

```

22

23

## Basic Usage

24

25

```typescript

26

import { CLI } from "@tarojs/cli";

27

28

// Initialize and run CLI

29

const cli = new CLI();

30

cli.run();

31

32

// Or use in custom Node.js scripts

33

import { Project, defineConfig } from "@tarojs/cli";

34

35

// Define Taro configuration

36

const config = defineConfig({

37

projectName: 'my-app',

38

framework: 'react',

39

compiler: 'webpack5',

40

// ... other config

41

});

42

```

43

44

**Command Line Usage:**

45

46

```bash

47

# Initialize new project

48

taro init my-project

49

50

# Build for specific platform

51

taro build --type weapp

52

53

# Start development server

54

taro build --type h5 --watch

55

56

# Create new page

57

taro create

58

59

# Run project diagnostics

60

taro doctor

61

```

62

63

## Architecture

64

65

Taro CLI is built around several key components:

66

67

- **CLI Engine**: Main command processor handling argument parsing and command routing

68

- **Service Kernel**: Plugin system for extensible command and platform support

69

- **Creation System**: Project, page, and plugin scaffolding with template management

70

- **Build System**: Multi-platform compilation with framework and compiler abstraction

71

- **Configuration System**: Type-safe configuration with environment-specific overrides

72

- **Diagnostic System**: Project health checks and recommendations

73

74

## Capabilities

75

76

### Command-Line Interface

77

78

Main CLI class that handles command parsing, environment setup, and command execution for all Taro operations.

79

80

```typescript { .api }

81

class CLI {

82

constructor(appPath?: string);

83

run(): Promise<void>;

84

parseArgs(): Promise<void>;

85

}

86

```

87

88

[Command-Line Interface](./cli.md)

89

90

### Project Creation

91

92

Comprehensive project scaffolding system with support for multiple frameworks, templates, and customization options.

93

94

```typescript { .api }

95

class Project extends Creator {

96

constructor(options: IProjectConf);

97

init(): Promise<void>;

98

create(): Promise<void>;

99

}

100

101

interface IProjectConf {

102

projectName: string;

103

projectDir: string;

104

npm: NpmType;

105

templateSource: string;

106

framework: FrameworkType;

107

typescript?: boolean;

108

css: CSSType;

109

template: string;

110

description?: string;

111

autoInstall?: boolean;

112

}

113

```

114

115

[Project Creation](./project-creation.md)

116

117

### Page and Component Creation

118

119

Utilities for creating pages and components within existing Taro projects, with automatic configuration updates.

120

121

```typescript { .api }

122

interface IPageConf {

123

projectDir: string;

124

projectName: string;

125

pageName: string;

126

framework: FrameworkType;

127

css: CSSType;

128

typescript?: boolean;

129

pageDir?: string;

130

subPkg?: string;

131

}

132

133

function modifyPagesOrSubPackages(

134

configPath: string,

135

pagePath: string,

136

subPackage?: string

137

): ConfigModificationState;

138

```

139

140

[Page Creation](./page-creation.md)

141

142

### Plugin Development

143

144

Plugin creation and management system for extending Taro functionality with custom build processes and platform support.

145

146

```typescript { .api }

147

class Plugin extends Creator {

148

constructor(options: IPluginConf);

149

create(): Promise<void>;

150

getCliVersion(): string;

151

}

152

153

interface IPluginConf {

154

pluginName: string;

155

type: string;

156

description?: string;

157

projectDir: string;

158

projectName: string;

159

template: string;

160

version: string;

161

}

162

```

163

164

[Plugin Development](./plugin-development.md)

165

166

### Configuration Management

167

168

Type-safe configuration system with environment-specific overrides and webpack merge capabilities.

169

170

```typescript { .api }

171

function defineConfig<T extends CompilerTypes = CompilerWebpackTypes>(

172

config: UserConfigExport<T>

173

): UserConfigExport<T>;

174

175

interface ConfigEnv {

176

command: string;

177

mode: string;

178

}

179

180

type UserConfigFn<T extends CompilerTypes = CompilerWebpackTypes> = (

181

merge: WebpackMerge,

182

env: ConfigEnv

183

) => IProjectConfig<T> | Promise<IProjectConfig<T>>;

184

185

type UserConfigExport<T extends CompilerTypes = CompilerWebpackTypes> =

186

| IProjectConfig<T>

187

| Promise<IProjectConfig<T>>

188

| UserConfigFn<T>;

189

```

190

191

[Configuration](./configuration.md)

192

193

### Project Diagnostics

194

195

Comprehensive project health checking system that validates environment, configuration, packages, and provides recommendations.

196

197

```typescript { .api }

198

const doctor: {

199

validators: Array<(args?: any) => Promise<void> | void>;

200

};

201

```

202

203

[Diagnostics](./diagnostics.md)

204

205

### Utility Functions

206

207

Core utility functions for path resolution, package management, file operations, and development helpers.

208

209

```typescript { .api }

210

function getRootPath(): string;

211

function getPkgVersion(): string;

212

function getAllFilesInFolder(folder: string, filter?: string[]): Promise<string[]>;

213

function getTemplateSourceType(url: string): TemplateSourceType;

214

function printPkgVersion(): void;

215

```

216

217

[Utilities](./utilities.md)

218

219

## Types

220

221

```typescript { .api }

222

type FrameworkType = 'react' | 'vue3' | 'preact' | 'solid';

223

type CompilerTypes = 'webpack5' | 'vite' | 'esbuild';

224

type CSSType = 'sass' | 'stylus' | 'less' | 'none';

225

type NpmType = 'npm' | 'yarn' | 'pnpm' | 'cnpm';

226

type TemplateSourceType = 'git' | 'url';

227

228

interface FileStat {

229

name: string;

230

isDirectory: boolean;

231

isFile: boolean;

232

}

233

234

enum ConfigModificationState {

235

Success = 'SUCCESS',

236

Fail = 'FAIL'

237

}

238

239

type WebpackMerge = (...configs: Array<object | null | undefined>) => object;

240

```

241

242

## Supported Platforms

243

244

- **weapp**: WeChat Mini Program

245

- **alipay**: Alipay Mini Program

246

- **swan**: Baidu Smart Program

247

- **tt**: ByteDance Mini Program

248

- **qq**: QQ Mini Program

249

- **jd**: JD Mini Program

250

- **h5**: HTML5 Web

251

- **rn**: React Native

252

- **harmony-hybrid**: Harmony Hybrid