簡體   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