[英]Using gulp-minify-html and gulp-html-replace together
我正在將Gulp與gulp-minify-html
和gulp-html-replace
:
var minifyhtml = require('gulp-minify-html');
var htmlreplace = require('gulp-html-replace');
var dev_paths = {
HTML: dev + '/**/*.html'
};
var prod_paths = {
RELATIVE_CSS: ['css/bootstrap.css', 'css/font-awesome.css', 'css/c3.css', 'css/main.css'],
};
//Compress HTML
gulp.task('minify-html', function () {
var opts = {
empty: true,
comments: true
};
return gulp.src(dev_paths.HTML)
.pipe(minifyhtml(opts))
.pipe(gulp.dest(prod + '/'));
});
//Add call to the JS and CSS in the HTML files
gulp.task('replace-files', function() {
gulp.src(dev_paths.HTML)
.pipe(htmlreplace({
'css': prod_paths.RELATIVE_CSS,
'js': 'js/script.js'
}))
.pipe(gulp.dest('public/prod/'));
});
gulp.task('prod',['replace-files','minify-html'], function(){
})
但是,HTML不會用任務replace-files
我指定的CSS和JS replace-files
。 當我運行gulp而不執行minify-html
任務時,它工作正常。
有誰知道為什么同時使用replace-files
和minify-html
這兩個任務不起作用?
謝謝。
由於任務是並行運行的,因此可能在“替換文件”任務完成之前運行“ minify-html”任務。
嘗試使用運行順序以確保任務按要求的順序運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.