Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli):给config的copy加上watch选项,使之可以监听并复制 #4843

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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