【发布时间】:2015-06-22 20:23:09
【问题描述】:
编辑:看来 Jade 的 pretty:true 是问题所在。知道为什么吗?
我在这里遇到了一些麻烦。让我解释一下我要做什么:
这是应该发生的事情:
file.jade > intermediate.html > index.html
jade 文件输出一个 html,然后 html 输出一个缩小的 html。当然都是手表功能。
为了达到这个效果我写的:
/* ===== TEMPLATES ===== */
gulp.task('templates', function() {
gulp.src(src + '/*.jade')
.pipe(jade({ locals: {data: data}, pretty:true}))
.pipe(rename('intermediate.html'))
.pipe(gulp.dest(src));
})
/* ===== HTML ===== */
gulp.task('html', function() {
// Get file
return gulp.src('./src/intermediate.html')
.pipe(inlineCss({
applyStyleTags: true,
applyLinkTags: true,
removeStyleTags: true,
removeLinkTags: true
}))
.pipe(inject(gulp.src([src + '/responsive.css']), {
starttag: '<!-- inject:head:{{ext}} -->',
transform: function (filePath, file) {
// return file contents as string
return file.contents.toString('utf8')
}
}))
.pipe(rename('index.html'))
.pipe(minifyHTML(options))
// Output file
.pipe(gulp.dest(archive))
.pipe(gulp.dest(dest));
});
/* ===== WATCH ===== */
gulp.task('watch', function() {
// Folders to watch and tasks to execute
gulp.watch([src + '/template.jade'], ['default']);
});
/* ===== DEFAULT ===== */
// Default gulp task ($ gulp)
gulp.task('default', function(callback) {
runSequence('clean',
'templates',
'html',
'notify',
callback);
});
现在构建发生时会发生什么? file.jade 输出 middle.html 但是 index.html 是用OLD intermediate.html 版本生成的,在它由玉模板生成之前。解释起来有点棘手。
我的意思是我每次都需要连续执行 2 次才能获得最新的 index.html !因为 index.html 采用了从jade 编译模板之前存在的intermediate.html 版本。我希望我说的足够清楚
我认为运行序列可以,但似乎不是!
【问题讨论】:
标签: javascript html node.js pug gulp