无法让 gulp-rev-replace 与 gulp-useref 一起使用

Can#39;t get gulp-rev-replace working with gulp-useref(无法让 gulp-rev-replace 与 gulp-useref 一起使用)
本文介绍了无法让 gulp-rev-replace 与 gulp-useref 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

继续我之前的 问题 - 但这次是下一步:让文件修订工作.

Continuing my previous question - but this time is the next step: getting file revisions to work.

我正在学习 johnpapa 的 Gulp 自动化课程,但似乎遇到了另一面墙(当您尝试将简明课程调整为不同的文件结构时,您会遇到这种情况:P).

I'm working through johnpapa's course on automation with Gulp and seem to hit another wall (that's what you get when you try to adapt a concise course to a different file structure :P ).

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

Basically, the issue is that I do get files named with a revision, but those names do not get into the end-result test.jsp, and I can't figure out why...

这是任务(为简洁起见省略了缩小,但它适用于文件修订):

This is the task (the minification is omitted for brevity, but it works fine with the file revisioning):

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.

inject is the task that injects css and js references to the index file (works correctly), $ is require('gulp-load-plugins')({lazy: true}) and config.indexFile is index.jsp.

replaceDirectory 函数是(使用因为 rev-manifest 生成完整路径名):

The replaceDirectory function is (used since the rev-manifest generates full pathnames):

function replaceDirectory(path) {

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

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

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

My file structure (unlike the one in the course) is:

- 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)

基本上,index.jsp 是针对 CSS 和 JS 库和应用程序资产进行处理的,这些资产被缩小并连接成 lib.css、lib.js、app.css 和 app.js.之后,所有这些都被注入到 index.jsp 的副本中,该副本称为 test.jsp.

Basically, index.jsp is processed for CSS and JS library and application assets, which are minified and concatenated into lib.css, lib.js, app.css and app.js. Later all these are injected into a copy of index.jsp which is called test.jsp.

资产收集、连接、注入工作和磁盘上的文件修改工作出色.test.jsp中文件名的更新——没那么多...

The asset gathering, concatenation, injection works and file revisions on disk work splendidly. The update of file names in test.jsp- not so much...

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

Any ideas or pointers will be appreciated.

推荐答案

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

You have to add replaceInExtensions: '.jsp' to your options for revReplace().

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

I had this problem for a day and a half before I looked at the plugin code and figured it out. I'm using .php files. The documentation does say you need to do this but it's easily missed.

希望对你有帮助.

这篇关于无法让 gulp-rev-replace 与 gulp-useref 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)