ChaseMoskal
ChaseMoskal

Reputation: 7681

Basic Gulp Uglify Setup?

I want to take all .js files in my project, and for each, save a minified version in the same directory.

That is, given this project directory structure:

project/
    gulpfile.js
    basic.js
    Project/
        Project.js
        Toolbelt.js
        Colors/
            RGBA.js
            HSLA.js

My gulpfile should create these minified files:

project/
    basic.js
    basic.min.js // ADDED BY GULP
    Project/
        Project.js
        Project.min.js // ADDED BY GULP
        Toolbelt.js
        Toolbelt.min.js // ADDED BY GULP
        Colors/
            RGBA.js
            RGBA.min.js // ADDED BY GULP
            HSLA.js
            HSLA.min.js // ADDED BY GULP

These seems like it should be relatively straightforward, but I seem to have missed it. I'm not sure what I'm doing wrong, but it only seems to work on basic.js (basic.min.js is created successfully), but it's not working for any files within folders. I'm not sure if **.js isn't working as I'm expecting, or gulp.dest('') isn't pointing to the current file's directory.. I've done some experimenting off this, and I'm stumped.

var gulp   = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');

gulp.task('js-minify', function(){
    return gulp.src(['**.js', '!gulpfile.js', '!**.min.js'])
        .pipe(uglify())
        .pipe(rename(function(path){
            path.extname = '.min.js';
         }))
        .pipe(gulp.dest(''));
});

Running gulp js-minify from the command line does not yield the results I'm looking for.

What am I doing wrong?

Upvotes: 1

Views: 289

Answers (1)

Daryl Ginn
Daryl Ginn

Reputation: 1424

Your issue is your gulp.src paths, you're not looking in directories:

['**/*.js', '!gulpfile.js', '!**/*.min.js'] 

Upvotes: 3

Related Questions