[英]Gulp.src match folder with square brackets
I've automated all tasks from my project using gulp.我已经使用 gulp 自动化了我项目中的所有任务。
However I have a specific name folder with square brackets in its name (yes, it's required to have square brackets in it's name on purpose) and this seems not to work with gulp.但是,我有一个名称中带有方括号的特定名称文件夹(是的,它的名称中必须有方括号),这似乎不适用于 gulp。 I need to target that folder and minify the javascript in it.
我需要定位该文件夹并缩小其中的 javascript。 I tried using a regex match pattern, but as long as I read gulp is using blob or either I don't understand blob or I am doing this wrong
我尝试使用正则表达式匹配模式,但只要我阅读 gulp 正在使用 blob 或者我不理解 blob 或者我做错了
Let's say I have a folder named with scripts inside of it: [testFolder] > script1.js, script2.js This is how I target it with code.假设我有一个以脚本命名的文件夹: [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
}
What am I doing wrong?我究竟做错了什么?
Use \\
for escaping []
.将
\\
用于 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
}
For more information read globs/segments-and-separators and How do I match a square bracket literal using RegEx有关更多信息,请阅读glob/segments-and-separators和How do I match a square bracket literal using RegEx
Okay, after some days of trying to make it work, it seems this is working for both macOS / linux and Windows (tested on windows 10) Thanks for @Saeed help in the answer below.好的,经过几天的尝试,它似乎适用于 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
}
This is for windows这是针对 windows
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.