我已经使用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
}
我究竟做错了什么?
最佳答案
使用\\
转义[]
。
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
}
有关更多信息,请阅读globs/segments-and-separators和How do I match a square bracket literal using RegEx