Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent gulp to minify code on local machine

I started a project with [RDash angular dashboard][1] which using gulp. this is the first time I work with gulp and the problem is that while I'm working locally I can't debug because it minify css/js/html files.

How can I prevent from gulp to minify while working locally?

Here is what I have on gulpfile.js:

var gulp = require('gulp'),
usemin = require('gulp-usemin'),
wrap = require('gulp-wrap'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
minifyCss = require('gulp-minify-css'),
minifyJs = require('gulp-uglify'),
concat = require('gulp-concat'),
less = require('gulp-less'),
rename = require('gulp-rename'),
minifyHTML = require('gulp-minify-html');

var paths = {
scripts: 'src/js/**/*.*',
styles: 'src/less/**/*.*',
images: 'src/img/**/*.*',
templates: 'src/templates/**/*.html',
index: 'src/index.html',
bower_fonts: 'src/components/**/*.{ttf,woff,eof,svg}',
};

/**
 * Handle bower components from index
   */
   gulp.task('usemin', function() {
return gulp.src(paths.index)
    .pipe(usemin({
        js: [minifyJs(), 'concat'],
        css: [minifyCss({keepSpecialComments: 0}), 'concat'],
    }))
    .pipe(gulp.dest('dist/'));
});

/**
 * Copy assets
   */
gulp.task('build-assets', ['copy-bower_fonts']);

gulp.task('copy-bower_fonts', function() {
return gulp.src(paths.bower_fonts)
    .pipe(rename({
        dirname: '/fonts'
    }))
    .pipe(gulp.dest('dist/lib'));
});

/**
 * Handle custom files
 */
gulp.task('build-custom', ['custom-images', 'custom-js', 'custom-less',         'custom-templates']);

gulp.task('custom-images', function() {
return gulp.src(paths.images)
    .pipe(gulp.dest('dist/img'));
});

gulp.task('custom-js', function() {
return gulp.src(paths.scripts)
    .pipe(minifyJs())
    .pipe(concat('dashboard.min.js'))
    .pipe(gulp.dest('dist/js'));
});

gulp.task('custom-less', function() {
return gulp.src(paths.styles)
    .pipe(less())
    .pipe(gulp.dest('dist/css'));
});

gulp.task('custom-templates', function() {
return gulp.src(paths.templates)
    .pipe(minifyHTML())
    .pipe(gulp.dest('dist/templates'));
});

/**
 * Watch custom files
 */
gulp.task('watch', function() {
gulp.watch([paths.images], ['custom-images']);
gulp.watch([paths.styles], ['custom-less']);
gulp.watch([paths.scripts], ['custom-js']);
gulp.watch([paths.templates], ['custom-templates']);
gulp.watch([paths.index], ['usemin']);
});

/**
 * Live reload server
 */
gulp.task('webserver', function() {
connect.server({
    root: 'dist',
    livereload: true,
    port: 8888
});
});

gulp.task('livereload', function() {
gulp.src(['dist/**/*.*'])
    .pipe(watch())
    .pipe(connect.reload());
});

/**
 * Gulp tasks
 */
gulp.task('build', ['usemin', 'build-assets', 'build-custom']);
gulp.task('default', ['build', 'webserver', 'livereload', 'watch']);
like image 991
Lior Bachar Avatar asked Oct 29 '15 08:10

Lior Bachar


1 Answers

You should add gulp-minify and use it as follows:

var minify = require('gulp-minify');

gulp.task('compress', function() {
  gulp.src('lib/*.js')
    .pipe(minify({
        exclude: ['tasks'],
        ignoreFiles: ['.combo.js', '-min.js']
    }))
    .pipe(gulp.dest('dist'))
});

Pass the files that you dont want to minify to the exclude.

In your code, you have specified that you want to minify all of the files here:

  gulp.task('usemin', function() {
   return gulp.src(paths.index)
    .pipe(usemin({
        js: [minifyJs(), 'concat'],
        css: [minifyCss({keepSpecialComments: 0}), 'concat'],
    }))
    .pipe(gulp.dest('dist/'));
});

In line

.pipe(usemin({..}) 

Just dont use this usemin task, and you should be fine

like image 70
uksz Avatar answered Sep 17 '22 15:09

uksz