Gulp不编译我的文件

时间:2016-01-19 16:25:28

标签: javascript gulp

我创建了以下gulpfile.js,但是当我在终端中键入gulp时,它没有给出任何错误,但它也没有在dist / assets /文件夹中编译我的文件:

/* Setup Gulp
   ========================================================================== */

// Require

var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    cssnano = require('gulp-cssnano'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    livereload = require('gulp-livereload'),
    del = require('del');


/* Tasks
   ========================================================================== */

// Styles

gulp.task('styles', function() {
  return sass('src/styles/main.scss', { style: 'expanded' })
    .pipe(autoprefixer('last 2 version'))
    .pipe(gulp.dest('dist/assets/css'))
    .pipe(rename({suffix: '.min'}))
    .pipe(cssnano())
    .pipe(gulp.dest('dist/assets/css'))
    .pipe(notify({ message: 'Styles task complete' }));
});

// Scripts

gulp.task('scripts', function() {
  return gulp.src('src/scripts/**/*.js')
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('dist/assets/js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('dist/assets/js'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

// Images

gulp.task('images', function() {
  return gulp.src('src/images/**/*')
    .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
    .pipe(gulp.dest('dist/assets/img'))
    .pipe(notify({ message: 'Images task complete' }));
});

// Fonts

gulp.task('fonts', function() {
  return gulp.src('src/fonts/**/*')
    .pipe(gulp.dest('dist/assets/fonts'))
    .pipe(notify({ message: 'Fonts task complete' }));
});

// Clean the assets folder

gulp.task('clean', function() {
    return del(['dist/assets/css', 'dist/assets/js', 'dist/assets/img', 'dist/assets/fonts']);
});

// Default task - gulp
// The clean task will launch before all the others

gulp.task('default', ['clean'], function() {
    gulp.start('styles', 'scripts', 'images', 'fonts');
});

// Gulp watch task

gulp.task('watch', function() {

  // Watch .scss files
  gulp.watch('src/styles/**/*.scss', ['styles']);

  // Watch .js files
  gulp.watch('src/scripts/**/*.js', ['scripts']);

  // Watch image files
  gulp.watch('src/images/**/*', ['images']);

  // Watch font files
  gulp.watch('src/fonts/**/*', ['fonts']);

  // Create LiveReload server
  livereload.listen();

  // Watch any files in dist/, reload on change
  gulp.watch(['dist/**']).on('change', livereload.changed);

});

“gulp”突击队员给出了这样的反馈:

[17:18:04] Using gulpfile ~/Desktop/test/gulpfile.js
[17:18:04] Starting 'default'...
[17:18:04] Starting 'styles'...
[17:18:04] Starting 'scripts'...
[17:18:04] Starting 'images'...
[17:18:04] Starting 'fonts'...
[17:18:04] Finished 'default' after 60 ms
[17:18:04] Finished 'scripts' after 53 ms
[17:18:04] gulp-imagemin: Minified 0 images
[17:18:04] Finished 'images' after 36 ms
[17:18:04] Finished 'fonts' after 30 ms
[17:18:04] OptionParser::NeedlessArgument: needless argument: --sourcemap=none
  Use --trace for backtrace.
[17:18:04] Finished 'styles' after 259 ms

1 个答案:

答案 0 :(得分:0)

在你的样式任务中,尝试使用gulp.src方法指向你想要它处理的文件

例如:

gulp.task('styles', function() {
  return gulp.src('src/styles/main.scss')
    .pipe(sass({style: 'expanded'}))
    ...
});