【问题标题】:Verify if certain string exists in html page验证 html 页面中是否存在某个字符串
【发布时间】:2018-09-10 11:00:53
【问题描述】:

我的文件夹中有一些 js 和 html 文件,我想验证没有 js 文件或 html 文件包含 http:// 对于 js 文件,我使用了 gulp-contains,它运行良好,但它不适用于 html 页面.我想要任何能够验证没有脚本引用 http:// 的 gulp 模块意味着如果 html 包含 <script src="http://cdn...." 那么它应该抛出错误并且只有在脚本引用 https 时才应该工作。 这是我尝试过的:

gulp.task('IsHttpExists', function () {
    gulp.src(['scripts/*.js', 'pages/*.html'])
        .pipe(contains({
            search: 'http://',
            onFound: function (string, file, cb) {
                console.log(file.path);
                var sFile = require('path').parse(file.path).base;
                var error = 'The file "' + sFile + '" contains "' + string + '"';
                cb(new gutil.PluginError('gulp-contains', error));
            }
        }))
});

那么这是否可以使用 gulp-if 或其他一些 gulp 模块?

【问题讨论】:

    标签: html gulp gulp-if


    【解决方案1】:

    好的,所以我找到了答案,但我不确定是否有更好的方法。我认为 gulp-contains 无法读取 html 页面,所以我找到了一个 gulp-module "gulp-html-to-js",它将 html 转换为 js,然后 gulp-contains 可以找到字符串

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 2012-02-24
      • 2014-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多