我正在尝试使用GULP 4压缩一系列HTML和PHP文件。我遇到的一个问题是有些文件包含<pre>
标记。我不想压缩这些文件,因为它会弄乱文件。有没有一种方法可以使用GULP评估文件是否包含字符串<pre>
,如果包含,就避免对该文件进行压缩?下面是我的相关代码:
const gulp = require('gulp');
const {src, series, parallel, dest} = require('gulp');
const GulpReplace = require('gulp-replace');
function no_2_spaces_purchasingdemand_php()
{
console.log("no 2 spaces purchasingdemand_php")
return gulp.src
(
'dist/purchasingdemand/**/*.php'
, { base: "./" }
)
.pipe
(
GulpReplace(' ','☺☻')
)
.pipe
(
GulpReplace('☻☺','')
)
.pipe
(
GulpReplace('☺☻',' ')
)
.pipe(gulp.dest('./'))
}
exports.default = series(no_2_spaces_purchasingdemand_html)
1条答案
按热度按时间9w11ddsr1#
我不知道你是用什么来压缩文件,但这里是一个一般的例子:
gulp-htmlmin
本身--仅用于html文件--不会缩小html文件的<pre>...</pre>
部分。因此,如果你使用gulp-htmlmin
来缩小html文件,你不需要过滤掉那些带有<pre>
标签的文件。我还展示了如何使用
gulp-filter
插件根据文件内容进行过滤。它可以访问每个文件的内容。如果你不想让该文件传递到下一个pipe
,请从过滤函数返回false
。