2017-05-19 2 views
0

Ich habe ein Problem, ich baue eine Website mit Jekyll und Gulp. Wenn ich eine Javascript-Datei ändere, werden die .js-Dateien nicht automatisch aktualisiert, und ich muss das Projekt jedes Mal, wenn ich eine Änderung an den .js-Dateien vornehme, "neu einlesen".BrowserSync und Gulp aktualisieren keine Javascript-Dateien (jekyll)

Das ist mein Gulp Datei ist

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 , ['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', ['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('assets/css/main.scss') 
     .pipe(sass({ 
      includePaths: ['css'], 
      onError: browserSync.notify 
     })) 
     .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true })) 
     .pipe(gulp.dest('_site/assets/css')) 
     .pipe(browserSync.reload({stream:true})) 
     .pipe(gulp.dest('assets/css')); 
}); 

/* 
* Pug Stuff 
*/ 

gulp.task('pug', function(){ 
    return gulp.src('_pugfiles/*.pug') 
    .pipe(pug()) 
    .pipe(gulp.dest('_includes')); 
}); 




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

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

Antwort

0

Das erste, was ändern

var browserSync = require('browser-sync'); to--> 
var browserSync = require('browser-sync').create(); 

Zweitens fügen Sie die init() Aufruf:

browserSync.init({ 

Schließlich weiß ich nicht alles über Mops-Dateien, aber du wirst am Ende deiner Mops-Aufgabe nicht neu geladen.

+0

Es funktioniert nicht. –

Verwandte Themen