繁体   English   中英

Gulp 4手表未检测到变化

[英]Gulp 4 watch doesn't detect changes

是否有可能与一饮而尽v.4.0.0看文件夹以外的文件,其中gulpfile.js所在?

在较早版本的../../someFile.css ,可以将文件路径设置为../../someFile.css并监视其更改,但是在v4中,它无法检测到同一路径的更改。

 // snip.... let rootFolder = '..\\..\\root\\'; // Watch function let watchThis = (filePath, gulpTasks) => { gulp.watch(filePath, gulp.series(gulpTasks)) .on('change', function(path) { console.log(`${chalk.blue('Changed')}: ${chalk.yellow(path)}`); }) .on('unlink', function(path) { console.log(`${chalk.red('Deleted')}: ${chalk.yellow(path)}`); }); } // Watch task configuration let watchFiles = () => { watchThis([`${rootFolder}/style1.scss`, `${rootFolder}/style2.scss`], 'scss') watchThis('./js/main.js', 'js') } // Final watch task gulp.task('watch', gulp.series( 'development', gulp.parallel( watchFiles, 'startLiveServers' ) )); // ...snip 

将不会检测到对文件['../../style1.scss', '../../style2.scss']更改,但它们将适用于'./js/main.js' 我想念什么吗?

新的Gulp 4监视任务存在问题。 与Gulp 3中的watch任务不同,新版本不可原谅,并且需要具有正确路径分隔符的正确路径结构。

因此,我们不能使用可能导致..\\\\..\\\\root\\\\/style1.scss路径,而必须将路径转换为../../root/style1.scss类的适当结构。

这个简单的函数有帮助,其余的由gulp和nodejs处理

let fixPath = (oldPath) => {
    const pathString = oldPath;
    const fix = /\\{1,}|\/{1,}/;

    return pathString.replace(new RegExp(fix, 'gm'), '/').replace(new RegExp(fix, 'gm'), '/')
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM