提交 30822941 编写于 作者: fxy060608's avatar fxy060608

chore: 调整 watcher 日志输出

上级 821b8a28
......@@ -10,11 +10,9 @@ export type UniViteCopyPluginTarget = Omit<FileWatcherOptions, 'verbose'> & {
}
export interface UniViteCopyPluginOptions {
targets: UniViteCopyPluginTarget[]
verbose: boolean
}
export function uniViteCopyPlugin({
targets,
verbose,
}: UniViteCopyPluginOptions): Plugin {
let resolvedConfig: ResolvedConfig
let initialized = false
......@@ -46,7 +44,6 @@ export function uniViteCopyPlugin({
{ setTimeout, clearTimeout }
)
new FileWatcher({
verbose,
...target,
}).watch(
{
......
import fs from 'fs-extra'
import path from 'path'
import debug from 'debug'
import { type FSWatcher, type WatchOptions, watch } from 'chokidar'
import { isArray } from '@vue/shared'
import { pathToGlob } from './utils'
......@@ -8,20 +9,19 @@ export interface FileWatcherOptions {
src: string | string[]
dest: string
transform?: FileTransform
verbose?: boolean
}
const debugWatcher = debug('uni:watcher')
export class FileWatcher {
private src: string[]
private dest: string
private transform?: FileTransform
private verbose?: boolean
private watcher!: FSWatcher
private onChange?: () => void
constructor({ src, dest, transform, verbose }: FileWatcherOptions) {
constructor({ src, dest, transform }: FileWatcherOptions) {
this.src = !isArray(src) ? [src] : src
this.dest = dest
this.transform = transform
this.verbose = verbose
}
watch(
watchOptions: WatchOptions & { cwd: string },
......@@ -100,7 +100,7 @@ export class FileWatcher {
type: 'close' | 'copy' | 'remove' | 'add' | 'unwatch',
msg?: string | unknown
) {
this.verbose && console.log(type, msg)
debugWatcher.enabled && debugWatcher(type, msg)
}
from(from: string) {
return path.join(this.watcher.options.cwd!, from)
......
......@@ -71,7 +71,6 @@ export function uniCopyPlugin({
)
return uniViteCopyPlugin({
targets,
verbose: process.env.DEBUG ? true : false,
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册