必须不止一次运行gulp以获取样式更改
我在编译我的CSS时遇到了问题,当我在SASS文件中进行更改时,它不会更改最终文件,只需尝试多次。
var gulp = require('gulp'); var sass = require('gulp-sass'); var rename = require('gulp-rename'); var postcss = require('gulp-postcss'); var autoprefixer = require('autoprefixer'); var cssnano = require('cssnano'); var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); //CSS Tasks gulp.task('styles', function() { console.log("Compilling SASS"); gulp.src('app/sass/style.scss') .pipe(sass().on('error', sass.logError)) .pipe(postcss([ autoprefixer() ])) .pipe(rename('999_style.css')) .pipe(gulp.dest('app/css/')); }); gulp.task('stylescompress', ['styles'], function() { console.log("Concating and moving all the css files in styles folder"); gulp.src("app/css/**.css") .pipe(concat('style.css')) .pipe(postcss([ cssnano() ])) .pipe(gulp.dest('css/')); }); //Javascript Tasks gulp.task('jscompress', function() { //console.log("Concating and moving all the js files in javascript folder"); gulp.src("app/js/**.js") .pipe(concat('scripts.js')) .pipe(gulp.dest('js/')) .pipe(rename('scripts.min.js')) .pipe(uglify()) .pipe(gulp.dest('js/')) }); //Watch task gulp.task('default',function() { gulp.watch(['app/sass/**/*.scss'],['stylescompress']) .on('change', function(event) { console.log('SASS - File ' + event.path + ' was ' + event.type + ', running tasks...'); }); gulp.watch(['app/js/**/*.js'],['jscompress']) .on('change', function(event) { console.log('SCRIPTS - File ' + event.path + ' was ' + event.type + ', running tasks...'); }); });
正如你所看到的,我根据Gulp Docs使用了所有的功能,但是我没有发现发生了什么。
我错过了完成时的回报,让Gulp明白它何时应该调用下一个任务,它被记录在Gulp Docs中
我使用这个流来让每个任务结束时都能理解,就像这样:
gulp.task('somename', function() {
var stream = gulp.src('client/**/*.js')
.pipe(minify())
.pipe(gulp.dest('build'));
return stream;
});
链接地址: http://www.djcxy.com/p/32931.html
上一篇: Have to run gulp more than once to get Style changes
下一篇: Browserify + Babelify Gulp task is not terminating, when Watchify is used