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[]