問題描述
繼續我之前的 問題 - 但這次是下一步:讓文件修訂工作.
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.indexFile
是 index.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 一起使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!