[英]Gulp not working
I'm trying to run this following gulp that I found on a jekkyl template. 我正在尝试运行在jekkyl模板上发现的以下gulp。 I'm running on node 4 in a Windows 8.1 and i'm not understanding why every time i get the:
我在Windows 8.1的节点4上运行,我不明白为什么每次我得到以下信息:
events.js:141
throw er; //Unhandled 'error' event
^
I got the impression that is something related to windows, because when I ran on linux i didn't have problems. 我的印象是与Windows有关,因为当我在linux上运行时,我没有遇到任何问题。
This is the gulp: 这是大口吃:
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
gulp.task('browser-sync', ['jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
gulp.task('stylus', function(){
gulp.src('src/styl/main.styl')
.pipe(plumber())
.pipe(stylus({
use:[koutoSwiss(), prefixer(), jeet(),rupture()],
compress: true
}))
.pipe(gulp.dest('_site/assets/css/'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('assets/css'))
});
gulp.task('js', function(){
return gulp.src('src/js/**/*.js')
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('assets/js/'))
});
gulp.task('imagemin', function() {
return gulp.src('src/img/**/*.{jpg,png,gif}')
.pipe(plumber())
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('assets/img/'));
});
gulp.task('watch', function () {
gulp.watch('src/styl/**/*.styl', ['stylus']);
gulp.watch('src/js/**/*.js', ['js']);
gulp.watch('src/img/**/*.{jpg,png,gif}', ['imagemin']);
gulp.watch(['*.html', '_includes/*.html', '_layouts/*.html', '_posts/*'], ['jekyll-rebuild']);
});
gulp.task('default', ['js', 'stylus', 'browser-sync', 'watch']);
Does anybody know why and could help me understanding? 有人知道为什么吗,可以帮助我理解吗?
Basically the main problem is in the following line: 基本上,主要问题在于以下几行:
gulp.task('default', ['js', 'stylus', 'browser-sync', 'watch']);
The task in the array occur concurrently. 阵列中的任务同时发生。 If scripts and styles can usually be processed concurrently, browserSync could hardly serve a folder that is maybe not yet created.
如果脚本和样式通常可以同时处理,则browserSync几乎无法提供可能尚未创建的文件夹。 You have to rework the build process to add some synchronization here.
您必须重新构建过程才能在此处添加一些同步。
I see also another problem in: 我还看到另一个问题:
// stylus task
.pipe(gulp.dest('_site/assets/css/'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('assets/css'))
or 要么
.pipe(gulp.dest('assets/js/'))
or 要么
.pipe(gulp.dest('assets/img/'));
You serve the _site
folder, but sometimes you copy to _site/assets/
, sometimes to assets/
. 您提供
_site
文件夹,但有时将复制到_site/assets/
,有时复制到_site/assets/
assets/
。 Also, you should remove the last gulp.dest
in the stylus
task. 另外,您应该删除
stylus
任务中的最后一个gulp.dest
。
I'm glad that you tried to help. 很高兴您尝试提供帮助。 Fortunatelly I discovered that the problem is the way that Windows run scripts.
我很幸运地发现问题是Windows运行脚本的方式。 I just added a ".bat" like below:
我刚刚添加了一个“ .bat”,如下所示:
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll.bat', ['build'], {stdio: 'inherit'})
.on('close', done);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.