Skip to content

Commit

Permalink
feat(cli):给config的copy加上watch选项,使之可以监听并复制 (#4843)
Browse files Browse the repository at this point in the history
  • Loading branch information
moonkop authored and luckyadam committed Nov 19, 2019
1 parent 4f43295 commit 671ab6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/taro-cli/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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} 文件不存在!`)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-cli/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export interface ICopyOptions {
patterns: {
from: string,
to: string,
ignore?: string[]
ignore?: string[],
watch?: boolean
}[],
options: {
ignore?: string[]
Expand Down

0 comments on commit 671ab6e

Please sign in to comment.