无法使用gulp-useref进行gulp-rev-replace工作 [英] Can't get gulp-rev-replace working with gulp-useref

查看:297
本文介绍了无法使用gulp-useref进行gulp-rev-replace工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我正在通过johnpapa的Gulp自动化课程工作,似乎打了另一面墙(这是当你尝试将一个简洁的课程适应不同的文件结构时得到的结果:P)。

基本上,问题是我得到的文件名为与一个修订,但这些名称不进入最终结果 test.jsp ,我不明白为什么......



这是一项任务(为了简洁省略缩小,但它在文件修改时可以正常工作):

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

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

返回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))
;
});

注入是注入css和js引用索引文件(正常工作), $ require('gulp-load-plugins')({lazy:true}) config.indexFile index.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;


$ / code $ / pre

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


   -  ModuleDir 
- dist
- css
- lib.css
- app.css
- 字体
- 图像
- js
- lib.js
- app.js
- css
- js
- web-app
- InnerDir
- index.jsp
- test.jsp
- package.json,bower.json等(全部所需的文件)

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



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

任何想法或指针都会您必须添加 replaceInExtensions:'.jsp' 您的选择为 revReplace()



在看了一天之前,我有这个问题一天半插件代码并找出它。我正在使用.php文件。该文件确实表示你需要这样做,但很容易错过。



希望它有帮助。


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

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

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

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)

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.

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.

解决方案

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

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.

Hope it helps.

这篇关于无法使用gulp-useref进行gulp-rev-replace工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆