繁体   English   中英

使用绝对路径时 gulp watch 不起作用?

[英]gulp watch not work when use absolute path?

我设置的是gulp开发环境,但是在gulp watcher中使用绝对路径的时候没有生效,请问gulp watcher支持绝对路径吗?

吞咽文件.js

gulp.task('watch', function() {
    gulp.watch(
        path.join(__dirname, 'public/css/**/*.css'), 
        gulp.parallel('dev:css', 'dev:cssImgs')
    );
});

我发现了同样的错误,很抱歉在 2019 年提出了这个问题。但是这个问题还没有解决。

似乎 watch 进程只接受以 unix 风格编写的相对路径。 它不接受绝对路径,甚至不接受带反斜杠的相对路径(Windows 样式)。

使用节点path清除路径在 Windows 上无济于事,因此唯一的解决方案是使用 node path.normalize('..\\your\\relative\\path\\')然后用/替换\\ .

我写了一个简单的函数,无论它在哪个操作系统上使用,我都会以 unix 方式规范化路径。

 /* This plugin is used to fix path separators for dynamically created links used for `gulp watch` command. It converts links like `../../some//path\with/wrong//\separators/` to `../../some/path/with/wrong/separators/` It also replaces `~` with user home directory path */ module.exports = (oldPath) => { const pathString = oldPath; const fix = /\\{1,}|\/{1,}/; const user_home = require('os').homedir(); return pathString.replace(new RegExp(fix, 'gm'), '/').replace(new RegExp(fix, 'gm'), '/').replace('~', user_home) }

将该代码保存为fixPath.js ,然后以这种方式使用它:

 const fixPath = require('./fixPath') let badPath = '../../some//path\with/wrong//\separators/' let goodPath = fixPath(badPath) // "../../some/path/with/wrong/separators/"

暂无
暂无

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

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