繁体   English   中英

无法使用gulp-useref进行gulp-rev-replace

[英]Can't get gulp-rev-replace working with gulp-useref

继续我的上一个问题 -但这是下一步:使文件修订生效。

我正在使用gulp进行johnpapa自动化方面的课程,似乎碰到了另一堵墙(这就是您尝试将简洁的课程适应不同的文件结构:P时得到的结果)。

基本上,问题是我确实获得了以修订版命名的文件,但是这些名称没有进入最终结果test.jsp ,而且我不知道为什么...

这是任务(为简洁起见,省略了缩小,但在文件修订中工作正常):

gulp.task('build-dev', ['inject'], function () {

    var assets = $.useref.assets({searchPath: ''});

    return gulp
        .src(config.indexFile)
        .pipe($.rename('test.jsp'))
        .pipe($.plumber())
        .pipe(assets)
        .pipe($.rev())
        .pipe(assets.restore())
        .pipe($.useref())
        .pipe($.revReplace({modifyUnreved: replaceDirectory, modifyReved: replaceDirectory}))
        .pipe(gulp.dest(config.indexLocation))
        .pipe($.rev.manifest())
        .pipe(gulp.dest(config.indexLocation))
        ;
});

inject是将css和js引用注入索引文件(正确工作)的任务, $require('gulp-load-plugins')({lazy: true})config.indexFileindex.jsp

replaceDirectory函数是(自rev-manifest生成完整路径名以来使用):

function replaceDirectory(path) {

    var strToReplace = '../..';
    var strToReplaceWith = process.cwd().replace(/\\/g, '/') + '/WebContent';

    if (path) {
        return path.replace(strToReplace, strToReplaceWith);
    } else {
        return path;
    }
}

我的文件结构(与本课程中的文件结构不同)是:

- ModuleDir
    - dist
        - css
            - lib.css
            - app.css
        - fonts
        - images
        - js
            - lib.js
            - app.js
    - css
    - js
    - web-app
        - InnerDir
            - index.jsp
            - test.jsp
    - package.json, bower.json, etc. (all the required files)

基本上,为CSS和JS库和应用程序资产处理index.jsp,这些资产和资源已缩小并连接到lib.css,lib.js,app.css和app.js。 后来,所有这些都注入到名为test.jsp的index.jsp副本中。

磁盘上的资产收集,连接,注入工作和文件修订非常出色。 test.jsp中文件名的更新-没那么多...

任何想法或指针将不胜感激。

您必须在revReplace()选项中添加replaceInExtensions: '.jsp'

在查看插件代码并弄清楚之前,我有一天半的时间遇到​​了这个问题。 我正在使用.php文件。 该文档确实说您需要这样做,但是很容易错过。

希望能帮助到你。

在此期间(除非我找到问题的根源或任何人可以提供帮助),我选择了不同的缓存清除方案:

gulp.task('build-dev', ['inject'], function () {

    var assets = $.useref.assets({searchPath: ''});
    var cb = Math.random();

    return gulp
        .src(config.indexFile)
        .pipe($.rename('test.jsp'))
        .pipe($.plumber())
        .pipe(assets)
        .pipe(assets.restore())
        .pipe($.useref())
        .pipe($.replace('dist/css/lib.css', 'dist/css/lib.css?cb=' + cb))
        .pipe($.replace('dist/css/app.css', 'dist/css/app.css?cb=' + cb))
        .pipe($.replace('dist/js/lib.js', 'dist/js/lib.css?cb=' + cb))
        .pipe($.replace('dist/js/app.js', 'dist/js/app.js?cb=' + cb))
        .pipe(gulp.dest(config.indexLocation))
        ;
});

这不是我想要的答案,而是我需要的答案。 :)

暂无
暂无

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

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