Search code examples
javascriptgulpgulp-watch

Outputting directory in Gulp


I've looked at a few other questions about Gulp, but I can't seem to pin down what's wrong with my code.

Problem: I am trying to output all of my subdirectories (of 'public') & the files within them into a new directory called 'dist'... Now when I run 'gulp' or 'gulp build' the console spits out no errors and no new directory shows up. Any help? I'm sure it's something simple I'm not seeing.

Here's what my file tree looks like:

file tree

'use strict';

var gulp = require('gulp'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
    sass = require('gulp-sass'),
    maps = require('gulp-sourcemaps');

gulp.task('concatJS', function() {
  return gulp.src(['public/js/jquery-2.1.4.min.js',
                    'public/js/Chart.min.js',
                    'public/js/constructor.js'])
    .pipe(concat('app.js'))
    .pipe(gulp.dest('public/js'));
});

gulp.task('minifyJS', ['concatJS'], function() {
  return gulp.src('public/js/app.js')
    .pipe(uglify())
    .pipe(rename('app.min.js'))
    .pipe(gulp.dest('public/js'));
});

gulp.task('compileSass', function() {
  return gulp.src('public/scss/style.scss')
    .pipe(maps.init())
    .pipe(sass())
    .pipe(maps.write('./'))
    .pipe(gulp.dest('public/css'));
});

gulp.task('watchSass', function() {
  gulp.watch('public/scss/*.scss', ['compileSass']);
});

gulp.task('build', ['minifyJS', 'compileSass'], function() {
  return gulp.src(['css/style.css', 'img/**', 'js/app.min.js', 'index.html'], {base: './'})
    .pipe(gulp.dest('dist'));
});

gulp.task('default', ['build']);

Thanks in advance!


Solution

  • Try:

    gulp.task('build', ['minifyJS', 'compileSass'], function() {
      return gulp.src(['public/css/style.css', 'public/img/**', 'public/js/app.min.js', 'public/index.html'], {base: './'})
        .pipe(gulp.dest('dist'));
    });
    
    gulp.task('default', ['build']);
    

    Not exactly sure which directory your gulp file is in. But chances are you might be reading the wrong directory.