小程序开发工具命令行启动配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/GreyBearChao/article/details/83579074

在cmd窗口中使用命令启动指定的小程序项目

命令形如: wechat -o miniapp-shops

1.自定义一个 wechat.bat 文件,输入以下代码:

@echo off
call C:"\Program Files (x86)\Tencent\微信web开发者工具\"cli.bat %1 %2

路径为开发工具的路径

2.修改 “C:\Program Files (x86)\Tencent\微信web开发者工具\cli.js” 文件:

// 添加如下代码:

let projectPath = process.argv.slice(1)
const currentList = ['miniapp-shops'] // 当前小程序项目名称数组

for (let i in currentList) {
	if (projectPath[2] === currentList[i]) {
		projectPath[2] = "C:\\Users\\dell\\new\\qianbao-list\\" + projectPath[2]
		break;
	} else {
		console.log('\n')
		console.log('请输入命令:wechat -o 项目名称')
		console.log('当前项目列表:' + currentList)
		console.log('\n')
		process.exit(0)
	}
}

//原projectPath: ['C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.js','-o','miniapp-shops']

const child = child_process.spawnSync(path.join(installDir, '.\\node.exe'), [CLI_JS_PATH].concat(projectPath), {...}

3.将wechat.bat文件的路径配置到环境变量中。

4.修改 “C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat” 文件

// 源代码:

@echo off
set CALLING_DIR=%cd%
cd /d %~dp0
.\node.exe .\cli.js %*
cd %CALLING_DIR%

// 修改为:

@echo off
set CALLING_DIR=%cd%
cd /d %~dp0
.\node.exe .\cli.js %*
cd C:"\Users\dell\new\qianbao-list\"%2

C:\Users\dell\new\qianbao-list\为小程序项目所在的父目录

5.启动:打开cmd窗口,输入:

wechat -o miniapp-shops

6.如需 npm start 启动项目,直接输入npm start

猜你喜欢

转载自blog.csdn.net/GreyBearChao/article/details/83579074