CSS pathing not aligning between gulp and underscores

280 Views Asked by At

I am creating a WordPress site but the CSS is not showing up. I think I have narrowed it down to the pathing not being correct. but whenever I try to fix up the pathing gulp creates a new CSS output. I am using underscores sassified and gulp sass which I don't think are metting the same path. I can get underscores get_stylesheet_uri to use a CSS file that successfully outputs styling on my page. but I can't get the path correct on my gulpfile to output to the same CSS file

var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync');
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var runSequence = require('run-sequence');

// Basic Gulp task syntax
gulp.task('hello', function() {
  console.log('Hello Zell!');
})

// Development Tasks 
// -----------------

// Start browserSync server
gulp.task('browserSync', function() {
    browserSync.init({
      proxy: "localhost/sewintune"
  });
  });

  gulp.task('sass', function() {
    return gulp.src('app/sass/**/*.scss') // Gets all files ending with .scss in app/scss and children dirs
      .pipe(sass().on('error', sass.logError)) // Passes it through a gulp-sass, log errors to console
      .pipe(gulp.dest('../wp-content/themes/sew-in-tune/app/css/styles.css')) // Outputs it in the css folder
      .pipe(browserSync.reload({ // Reloading with Browser Sync
        stream: true
      }));
  })

// Watchers
gulp.task('watch', function() {
  gulp.watch('app/sass/**/*.scss', ['sass']);
  gulp.watch('app/*.php', browserSync.reload);
  gulp.watch('app/js/**/*.js', browserSync.reload);
})

// Optimization Tasks 
// ------------------

// Optimizing CSS and JavaScript 
gulp.task('useref', function() {

  return gulp.src('app/*.php')
    .pipe(useref())
    .pipe(gulpIf('*.js', uglify()))
    .pipe(gulpIf('*.css', cssnano()))
    .pipe(gulp.dest('dist'));
});

// Optimizing Images 
gulp.task('images', function() {
  return gulp.src('app/images/**/*.+(png|jpg|jpeg|gif|svg)')
    // Caching images that ran through imagemin
    .pipe(cache(imagemin({
      interlaced: true,
    })))
    .pipe(gulp.dest('dist/images'))
});

// Copying fonts 
gulp.task('fonts', function() {
  return gulp.src('app/fonts/**/*')
    .pipe(gulp.dest('dist/fonts'))
})

// Cleaning 
gulp.task('clean', function() {
  return del.sync('dist').then(function(cb) {
    return cache.clearAll(cb);
  });
})

gulp.task('clean:dist', function() {
  return del.sync(['dist/**/*', '!dist/images', '!dist/images/**/*']);
});

// Build Sequences
// ---------------

gulp.task('default', function(callback) {
  runSequence(['sass', 'browserSync'], 'watch',
    callback
  )
})
1

There are 1 best solutions below

0
Mark On

This line is incorrect:

.pipe(gulp.dest('../wp-content/themes/sew-in-tune/app/css/styles.css')) // Outputs it in the css folder

gulp.dest takes a folderName not a filename. You code is probably creating a folder actually called styles.css.

Your gulp.src for a 'sass' task is typically a single file, like 'styles.scss', which imports your partials into it. [Not the only way to do it.] So that task might look like this:

gulp.task('sass', function() {
    return gulp.src('app/sass/**/styles.scss') 
      .pipe(sass().on('error', sass.logError))

      // with no other modification, the below is the directory linked to in your html + styles.css 

      .pipe(gulp.dest('../wp-content/themes/sew-in-tune/app/css')) 
      .pipe(browserSync.reload({ 
        stream: true
      }));