Gulp pipe (gulp.dest ()) does not produce any results

I am currently studying gulp.js. as I saw the tutorial and gulp.js documentation, this code:

gulp.src('js/*.js') .pipe(uglify()) .pipe(gulp.dest('minjs')); 

creates an enlarged javascript file with the creation of a new directory named 'minjs'. Of course, I installed gulp -uglity with the -dev-save option. there is no error message on the console, so I don’t know what the problem is. I tried gulp with "sudo" but still didn't work.

so I went to the root directory and searched the whole file system, but there is no file called "minjs", so I think it just does not work. Why is this happening? anyone knows this problem, it would be good why this is happening.

all source code:

 var gulp = require('gulp'); var uglify = require('gulp-uglify'); gulp.task('default', function() { console.log('mifying scripts...'); gulp.src('js/*.js') .pipe(uglify()) .pipe(gulp.dest('minjs')); }); 
+5
source share
1 answer

I had the same problem, you have to return the task inside the function:

 gulp.task('default', function() { return gulp.src("js/*.js") .pipe(uglify()) .pipe(gulp.dest('minjs')); 

In addition, minjs will not be a file, but a folder, all your mini files will be saved.

Finally, if you want to minimize only 1 file, you can specify it directly, the same with the destination location.

For instance:

 var gulp = require('gulp'); var browserify = require('browserify'); var source = require('vinyl-source-stream'); var uglify = require('gulp-uglify'); gulp.task('browserify', function() { return browserify('./src/client/app.js') .bundle() //Pass desired output filename to vinyl-source-stream .pipe(source('main.js')) // Start piping stream to tasks! .pipe(gulp.dest('./public/')); }); gulp.task('build', ['browserify'], function() { return gulp.src("./public/main.js") .pipe(uglify()) .pipe(gulp.dest('./public/')); }); 

Hope this helps!

+8
source

Source: https://habr.com/ru/post/1239665/


All Articles