From 05417e32e32a521e1b3ba2161819c77d21c2cf22 Mon Sep 17 00:00:00 2001 From: moonkop Date: Fri, 15 Nov 2019 11:58:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(cli):=E7=BB=99config=E7=9A=84copy=E5=8A=A0?= =?UTF-8?q?=E4=B8=8Awatch=E9=80=89=E9=A1=B9,=E4=BD=BF=E4=B9=8B=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=9B=91=E5=90=AC=E5=B9=B6=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/util/index.ts | 10 ++++++++++ packages/taro-cli/src/util/types.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/taro-cli/src/util/index.ts b/packages/taro-cli/src/util/index.ts index e3b6271cd2a5..73300589cf61 100644 --- a/packages/taro-cli/src/util/index.ts +++ b/packages/taro-cli/src/util/index.ts @@ -11,6 +11,7 @@ import * as minimatch from 'minimatch' import * as t from 'babel-types' import * as yauzl from 'yauzl' import * as findWorkspaceRoot from 'find-yarn-workspace-root' +import * as chokidar from 'chokidar'; import defaultBabelConfig from '../config/babel' import defaultUglifyConfig from '../config/uglify' @@ -559,6 +560,15 @@ export function copyFiles (appPath: string, copyConfig: ICopyOptions | void) { } } copyFileSync(from, to, copyOptions) + if (pattern.watch){ + const watcher = chokidar.watch(from,{ + persistent: true, + ignoreInitial: true + }) + watcher.on('change',(res) => { + copyFileSync(from, to, copyOptions); + }) + } } else { printLog(processTypeEnum.ERROR, '拷贝失败', `${pattern.from} 文件不存在!`) } diff --git a/packages/taro-cli/src/util/types.ts b/packages/taro-cli/src/util/types.ts index d72957ae87db..2150a62092f0 100644 --- a/packages/taro-cli/src/util/types.ts +++ b/packages/taro-cli/src/util/types.ts @@ -73,7 +73,8 @@ export interface ICopyOptions { patterns: { from: string, to: string, - ignore?: string[] + ignore?: string[], + watch?: boolean }[], options: { ignore?: string[]