chrome浏览器livereload插件安装了 但控制台提示gulp相关报错

livereload.crx已经安装,文件只要ctrl+s保存控制台就报错。
报错:

f:\project\gulpfile.js:40
        server.changed(file.path);
               ^

TypeError: server.changed is not a function
    at f:\project\gulpfile.js:40:16
    at Gaze.<anonymous> (F:\project\node_modules\.npminstall\glob-watcher\0.0.6\glob-watcher\index.js:18:14)
    at emitTwo (events.js:87:13)
    at Gaze.emit (events.js:172:7)
    at Gaze.emit (F:\project\node_modules\.npminstall\gaze\0.5.2\gaze\lib\gaze.js:129:32)
    at F:\project\node_modules\.npminstall\gaze\0.5.2\gaze\lib\gaze.js:415:16
    at StatWatcher._pollers.(anonymous function) (F:\project\node_modules\.npminstall\gaze\0.5.2\gaze\lib\gaze.js:326:7)
    at emitTwo (events.js:87:13)
    at StatWatcher.emit (events.js:172:7)
    at StatWatcher._handle.onchange (fs.js:1290:10)

配置:

var gulp = require('gulp'), //本地安装gulp所用到的地方
    less = require('gulp-less');
    notify = require('gulp-notify'),
    plumber = require('gulp-plumber');
    autoprefixer = require('gulp-autoprefixer');
    livereload = require('gulp-livereload');

gulp.task('testAutoFx', function () {
    gulp.src('src/css/index.css')
        .pipe(autoprefixer({
            browsers: ['last 2 versions', 'Android >= 4.0'],
            cascade: true, //是否美化属性值 默认:true 像这样:
            //-webkit-transform: rotate(45deg);
            //        transform: rotate(45deg);
            remove:true //是否去掉不必要的前缀 默认:true
        }))
        .pipe(gulp.dest('dist/css'));
});
//定义一个testLess任务(自定义任务名称)
gulp.task('testLess', function () {
    gulp.src('src/less/*.less')//该任务针对的文件
        .pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
        .pipe(less())//该任务调用的模块
        .pipe(gulp.dest('src/less/css'));//将会在src/css下生成index.css
});

//gulp.task('default',['testLess']); //定义默认任务

gulp.task('testWatch', function () {
    var server = livereload();
    gulp.watch('src/**/**/*.less', ['testLess']);
    gulp.watch('src/css/index.css',['testAutoFx']);
    gulp.watch('*.*', function (file) {
        server.changed(file.path);
    });
});
阅读 4.3k
2 个回答

改改代码:

gulp.task('testWatch', function () {
    gulp.watch('src/**/**/*.less', ['testLess']);
    gulp.watch('src/css/index.css',['testAutoFx']);
    gulp.watch('*.*', function (file) {
        gulp.src('*.*').pipe(livereload());
    });
});

看到很多网上的demo很简单,不知道为什么我会操作这么多……反正我就操作了这么多……

不知道你成功了没,没成功可以看看我写的文章,希望对你有帮助

推荐问题
宣传栏