【问题标题】:Object not defined in gulp对象未在 gulp 中定义
【发布时间】:2018-12-29 02:44:46
【问题描述】:
var gulp        = require('gulp');
var browserSync = require('browser-sync');
var sass        = require('gulp-sass');
var prefix      = require('gulp-autoprefixer');
var cp          = require('child_process');
var pug         = require('gulp-pug');

var jekyll   = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var messages = {
    jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};

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

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

/**
 * Wait for jekyll-build, then launch the Server
 */
gulp.task('browser-sync', gulp.series('sass', 'jekyll-build'), function() {
    browserSync({
        server: {
            baseDir: '_site'
        },
        notify: false
    });
});

/**
 * Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
 */
gulp.task('sass', function () {
  return gulp.src('raw-assets/sass/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.    pipe(gulp.dest('assets/css'))
});

/**
* Compile files from _pugfiles into _includes (for live injecting) and site 
(for future jekyll builds)
*/
gulp.task('pug', function buildHTML() {
  return gulp.src('_pugfiles/*.pug')
  .pipe(pug({
    // Your options in here.
    pretty: true
  }))
  .pipe(gulp.dest('_includes'));
});

/**
 * Watch scss files for changes & recompile
 * Watch html/md files/pug files, run jekyll & reload BrowserSync
 */
gulp.task('watch', function () {
    gulp.watch('assets/css/**', gulp.task('sass'));
    gulp.watch(['*.html', '_layouts/*.html', '_includes/*'], gulp.task('jekyll-rebuild'));
    gulp.watch(['_pugfiles/*.pug'], gulp.task('pug'));
});

    /**
     * Default task, running just `gulp` will compile the sass,
     * compile the jekyll site, launch BrowserSync & watch files.
     */
    gulp.task('default', gulp.series('browser-sync', 'watch'));

我改了

gulp.task('', []) 

到

gulp.task('', gulp.series())

但它仍然给出 sass undefined 的错误。 我将我的 gulp 升级到最新的 gulp 并且 gulpfile 不再工作。我希望能够运行 gulp 命令并以 gulp 4 之前的方式运行所有内容。除了恢复到旧版本的 gulp 之外,任何解决此问题的方法。

【问题讨论】:

    标签: npm gulp jekyll


    【解决方案1】:

    将您的'sass' 任务移到首次调用它的'browser-sync' 任务之前。

    我现在找不到参考,但我认为当您使用gulp.task 注册语法(而不是现在 gulp4 中实际推荐的函数)时,您无法引用稍后在文件中注册的任务.

    您的代码中还有其他一些错误。这一行(以及其他类似的行):

    gulp.task('browser-sync', gulp.series('sass', 'jekyll-build'), function() {
    

    应该是:

    gulp.task('browser-sync', gulp.series('sass', 'jekyll-build', function() {
    

    还有:

    gulp.task('jekyll-rebuild', gulp.task('jekyll-build'), function () {
        browserSync.reload();
    });
    

    应该是:

    gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function () {
        browserSync.reload();
    }));
    

    这是一个很好的migrating to gulp4 article.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 2021-12-04
      • 2016-10-01
      • 2011-03-24
      • 1970-01-01
      相关资源
      最近更新 更多