CSS路径在gulp和下划线之间未对齐

时间:2019-01-14 05:32:33

标签: php css sass gulp underscores-wp

我正在创建一个WordPress网站,但是CSS没有显示。我认为我已将其范围缩小到不正确的路径。但是每当我尝试修复路径gulp时,都会创建新的CSS输出。我使用的是强调的下划线和粗俗的粗俗,我认为这没什么问题。我可以使用下划线get_stylesheet_uri来使用CSS文件,该文件可以在页面上成功输出样式。但是我无法在gulpfile上获得正确的路径以输出到相同的CSS文件

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 个答案:

答案 0 :(得分:0)

此行不正确:

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

gulp.dest使用folderName而不是文件名。您的代码可能正在创建一个实际上称为styles.css的文件夹。

用于{sass}任务的gulp.src通常是单个文件,例如'styles.scss',该文件会将您的部分文件导入其中。 [不是唯一的方法。]因此,该任务可能看起来像这样:

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
      }));