0

My gulpfile is adding the compiled css and js files to both the dest (css / js) folders and the src (scss / coffee) folders.

The desired outcome is that the compiled files only print to the dest folders.

This is only happening when running gulp on Windows and not on Mac. Also, if I run the tasks without the watch, it compiles correctly; 'gulp styles' compiles the css files only to the css folder - 'gulp scripts' compiles the js files only to the js folder.

var gulp = require('gulp'),
    plumber = require('gulp-plumber'),
    rename = require('gulp-rename'),
    autoprefixer = require('gulp-autoprefixer'),
    coffee = require('gulp-coffee'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    minifycss = require('gulp-minify-css'),
    sass = require('gulp-sass');

gulp.task('styles', function () {
    return gulp.src(['scss/**/*.scss'])
        .pipe(plumber({
            errorHandler: function (error) {
                console.log(error.message);
                this.emit('end');
            }
        }))
        .pipe(sass())
        .pipe(autoprefixer('last 2 versions'))
        .pipe(gulp.dest('css/'))
        .pipe(rename({ suffix: '.min' }))
        .pipe(minifycss())
        .pipe(gulp.dest('css/'))
});

gulp.task('scripts', function () {
    return gulp.src('coffee/**/*.coffee')
        .pipe(plumber({
            errorHandler: function (error) {
                console.log(error.message);
                this.emit('end');
            }
        }))
        .pipe(coffee({ bare: true }))
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(gulp.dest('js/'))
        .pipe(rename({ suffix: '.min' }))
        .pipe(uglify())
        .pipe(gulp.dest('js/'))
});

gulp.task('default', function () {
    gulp.watch("scss/**/*.scss", ['styles']);
    gulp.watch("coffee/**/*.coffee", ['scripts']);
});
John Slegers
  • 45,213
  • 22
  • 199
  • 169
  • Locally, I tried to replicating this issue on windows but was unable to. My `node_modules` directory was in the same directory as the `coffee` and `scss` folders. What version of Windows, npm, and gulp are you currently using? Also are you possibly using a global version of gulp? – vandsh Feb 12 '16 at 19:54
  • Windows 7 - Latest versions of both node (5.6.0) and npm (3.6.0) - node_modules / coffee / scss folds should all be in the same directory, you are correct. Gulp is installed globally as it is necessary if you want to run gulp - what do you mean using that version? (the global and project level gulp are the same version). – Rolland Walsh Feb 12 '16 at 20:03
  • if you install gulp globally (`npm install -g gulp`, installs to `/Users//AppData/Roaming/npm/node_modules`) you could be running a different version than running gulp locally (`/node_modules`). Just looking for a possible version disparity when compared to your mac version. – vandsh Feb 12 '16 at 20:09
  • I understand what you're saying and that's what I mean by they are both same version of gulp (3.9.1). – Rolland Walsh Feb 12 '16 at 20:22

2 Answers2

0

This is because you are calling gulp.dest twice once before minification and once after minification. Calling dest writes file to disk on the path provided.

If you just want minified versions

For Css

.pipe(autoprefixer('last 2 versions'))
      .pipe(rename({ suffix: '.min' }))
      .pipe(minifycss())
      .pipe(gulp.dest('css/'))

For Js

pipe(jshint.reporter('default'))
      .pipe(rename({ suffix: '.min' }))
      .pipe(uglify())
      .pipe(gulp.dest('js/'))
WitVault
  • 23,445
  • 19
  • 103
  • 133
0

You possibly could try adding a . to the destination paths to help preserve the source path:

.pipe(gulp.dest('css/')) -> .pipe(gulp.dest('./css/'))

and

.pipe(gulp.dest('js/')) -> .pipe(gulp.dest('./js/'))
vandsh
  • 1,329
  • 15
  • 12