首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gulp.js文件和Jekyll有问题

Gulp.js文件和Jekyll有问题
EN

Stack Overflow用户
提问于 2014-11-06 17:45:53
回答 1查看 297关注 0票数 0

我的Gulp.js文件已经全部设置好了,但是我想不出如何在编译_site文件夹之后启动Jekyll任务。

gulp文件如下所示:

代码语言:javascript
复制
var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss = require('gulp-minify-css'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename'),
    clean = require('gulp-clean'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    plumber = require('gulp-plumber'),
    browserSync = require('browser-sync'),
    minifyHTML = require('gulp-minify-html'),
    cp = require('child_process');

//Source variables
var sassSources = ['components/sass/application.scss'];
var jsSources = ['components/js/*.js'];
var htmlSources = ['_site/**/*.html'];

gulp.task('styles', function() {
  return gulp.src(sassSources)
    .pipe(plumber())
    .pipe(sass({ style: 'expanded' }))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
    .pipe(gulp.dest('css'))
    .pipe(rename({suffix: '.min'}))
    .pipe(minifycss())
    .pipe(gulp.dest('css'))
    .pipe(gulp.dest('_site/css'))
    .pipe(browserSync.reload({stream:true}))
    .pipe(notify({ message: 'Styles task complete' }));
});

gulp.task('html', function() {
  var opts = {comments:false, spare:false, quotes: false, empty: false};

  gulp.src(htmlSources)
    .pipe(minifyHTML(opts))
    .pipe(gulp.dest('_site/'))
    .pipe(notify({ message: 'HTML minification complete' }));
});

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

gulp.task('clean', function() {
  return gulp.src(['stylesheets', 'javascripts'], {read: false})
    .pipe(clean());
});


//Build the Jekyll Site
gulp.task('jekyll-build', function (done) {
    browserSync.notify('Building Jekyll');
    return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
        .on('close', done);
});

//Rebuild Jekyll & do page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
    browserSync.reload();
});

//Wait for jekyll-build, then launch the Server
gulp.task('browser-sync', ['jekyll-build'], function() {
    browserSync.init(null, {
        server: {
            baseDir: '_site'
        },
        host: "localhost"
    });
});

gulp.task('watch', function() {
  // Watch .sass files
  gulp.watch('components/sass/**/*.scss', ['styles']);
  // Watch .js files
  gulp.watch(jsSources, ['scripts']);
  // Watch html files
  gulp.watch(['index.html', '_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);

});

gulp.task('default', ['clean'], function() {
    gulp.start('styles', 'scripts', 'browser-sync', 'html', 'watch');
});
EN

回答 1

Stack Overflow用户

发布于 2014-11-06 18:02:53

您必须在jekyll-build任务中指定html和样式任务的依赖项:

代码语言:javascript
复制
gulp.task('jekyll-build', ['styles', 'html'], function (done) {
    ...
}

还需要更改html任务,在gulp.src之前添加返回。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26785983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档