繁体   English   中英

Gulp.src 匹配文件夹带方括号

[英]Gulp.src match folder with square brackets

我已经使用 gulp 自动化了我项目中的所有任务。

但是,我有一个名称中带有方括号的特定名称文件夹(是的,它的名称中必须有方括号),这似乎不适用于 gulp。 我需要定位该文件夹并缩小其中的 javascript。 我尝试使用正则表达式匹配模式,但只要我阅读 gulp 正在使用 blob 或者我不理解 blob 或者我做错了

假设我有一个以脚本命名的文件夹: [testFolder] > script1.js, script2.js 这就是我使用代码定位它的方式。

function minifyJs() {
  return gulp.src('resources/[testFolder]/**/*.js') // not working
  return gulp.src('resources/\[.*testFolder\]/**/*.js) // not working either desipte I've tested 
       it on various things
    .pipe(minify({ noSource: true }))
    .pipe(gulp.dest('resources/[testFolder]')) // this is working pretty much fine
}

我究竟做错了什么?

\\用于 escaping []

function minifyJs() {
  return gulp.src('resources/\\[testFolder\\]/**/*.js') // not working
    .pipe(minify({ noSource: true }))
    .pipe(gulp.dest('resources/[testFolder]')) // this is working pretty much fine
}

有关更多信息,请阅读glob/segments-and-separatorsHow do I match a square bracket literal using RegEx

好的,经过几天的尝试,它似乎适用于 macOS / linux 和 Windows (在 windows 10 上测试)感谢@Saeed 的帮助。

// MAC / LINUX OS
function minifyJs() {
return gulp.src('resources/\\[testFolder\\]/**/*.js') // note the \\[name\\] escape here
 .pipe(minify({ noSource: true }))
 .pipe(gulp.dest('resources/[testFolder]')) // this is working for both
}

// WINDOWS
function minifyJs() {
return gulp.src('resources/[[]testFolder]/**/*.js') // note [[]name] escape here
  .pipe(minify({ noSource: true }))
  .pipe(gulp.dest('resources/[testFolder]')) // this is working for both
}

这是针对 windows

暂无
暂无

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

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