我目前正在使用WAMP运行本地服务器,我正在尝试设置Gulp.js。以下是我的gulpfile的内容:
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
minifyhtml = require('gulp-minify-html'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr();
gulp.task('styles', function() {
gulp.src('src/styles/main.scss')
.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('dist/assets/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('dist/css'))
.pipe(livereload(server))
.pipe(notify({ message: 'Styles task complete' }));
});
gulp.task('html', function() {
gulp.src('src/*.php')
.pipe(minifyhtml())
.pipe(gulp.dest('dist'))
.pipe(livereload(server))
.pipe(notify({ message: 'HTML task complete' }));
});
gulp.task('default', function() {
gulp.run('html');
});
以下是运行
gulp
时我得到的输出结果:[gulp] Using gulpfile C:\wamp\www\SawyerK\gulpfile.js
[gulp] Starting 'default'...
gulp.run() has been deprecated. Use task dependencies or gulp.watch task trigger
ing instead.
[gulp] Starting 'html'...
[gulp] Finished 'html' after 132 ms
[gulp] Finished 'default' after 134 ms
[gulp] gulp-notify: [Gulp notification] HTML task complete
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
根据我的发现,这个错误是由于其他应用程序正在使用Node想要使用的端口或类似情况引起的。但我不确定这是否正确,也不知道如何解决。有什么想法吗?谢谢!
编辑:如果有帮助的话,我似乎已经将其缩小到gulp-notify。
gulp.task('watch', function() { var server = livereload(); gulp.watch('src/**').on('change', function(file) { server.changed(file.path); }); gulp.watch('src/*.php', ['minifyhtml']); }); 编辑:这个评论怎么才能接受格式?我无法换行或格式化代码。
- Sawyer Knoblich符号,例如
var foo = "bar";`。 - 4ega