GULP
and I have the following problem, the code below, which simply minifies JS
and CSS
, works perfectly if you run the functions in default
and run GULP
. The problem is that with Watch
it does not work, it creates the file but it is blank.
Already answering some questions:
- Yes, it starts correctly, that is,
GULP
detects the change in the file and executes the function. - Yes, no
default
it minifies correctly. - Yes, if he does not have the minified file, he creates it, that is, he enters the function, but for some reason he can not read the
CSS
/JS
when the function is called byWatch
.
Code below:
var css = [
'./css/estilo.css'
];
var js = [
'./js/app.js'
];
var gulp = require('gulp');
var jsmin = require('gulp-jsmin');
var rename = require('gulp-rename');
var uglify = require("gulp-uglify");
var concat = require("gulp-concat");
var watch = require('gulp-watch');
var cssmin = require("gulp-cssmin");
var stripCssComments = require('gulp-strip-css-comments');
gulp.task('minify-css', function(){
gulp.src(css)
.pipe(stripCssComments({all: true}))
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./css/min/'));
});
gulp.task('minify-js', function () {
gulp.src(js)
.pipe(jsmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./js/min/'));
});
gulp.task('default', ['watch']);
gulp.task('watch', function() {
gulp.watch(js, ['minify-js']);
gulp.watch(css, ['minify-css']);
});
I have already tried to declare the path of CSS
directly in the function instead of calling the variable CSS
. I have already tried declaring the variable as global, but none of this changes the result that is the blank file.