12

i am currently learning about gulp.js. as i saw the tutorial and documentation of gulp.js, this code:

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

makes the uglified javascript file with create new directory named 'minjs'. of course, i installed gulp-uglity with --dev-save option. there is no error message on the console so i don't know what is the problem. i tried gulp with "sudo", but still not working.

so i went to the root directory and searched all filesystem but there is no file named 'minjs' so i guess it just not working. why this is happening? anyone knows this problem, it would be nice why this is happening.

whole 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'));
});
8
  • Can you try .pipe(gulp.dest('./minjs/'));? Jan 2, 2016 at 10:28
  • it will create minjs folder relative to the directory containing your gulpfile.js. Did you check there ?
    – Arkantos
    Jan 2, 2016 at 10:33
  • Arkantos// yep. i checked, no 'minjs' directory ;(
    – modernator
    Jan 2, 2016 at 10:40
  • Manasov Daniel// just i tried, but nothing happens either.
    – modernator
    Jan 2, 2016 at 10:41
  • how are you executing your gulp tasks ? You can go to the directory containing gulpfile.js and give gulp for executing default task. Do you see any errors while doing this ?
    – Arkantos
    Jan 2, 2016 at 11:05

2 Answers 2

10

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'));

Also, minjs will not be a file, but a folder, where all your minified files are going to be saved.

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

For example:

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 it helps!

0
1

Finally I resolved the question like this:

It was a directory mistake so the gulp task hasn't matched any files; then it couldn't create the dest directory (because no files in output).

const paths = {
  dest: {
    lib: './lib',
    esm: './esm',
    dist: './dist',
  },
  styles: 'src/components/**/*.less',
  scripts: ['src/components/**/*.{ts,tsx}', '!src/components/**/demo/*.{ts,tsx}'],
};

At first my scripts was ['components/**/*.{ts,tsx}', '!components/**/demo/*.{ts,tsx}']

And that hasn't matched any files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.