Gulp 不会看到任何变化 [英] Gulp wouldn't watch any changes

查看:15
本文介绍了Gulp 不会看到任何变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我摸不着头脑,但似乎无法弄清楚以下 gulpfile 有什么问题,它只是监视和编译较少的文件.

I am scratching my head around but can't seem to figure out whats wrong with the following gulpfile which simply watch and compile less file.

这简直不会少看变化,我已经尝试了所有的gulpgulp watch.我必须在每次更改后手动运行 gulp 来编译它们.是否有什么问题导致手表无法按预期工作?

This simply won't watch less changes, I have tried all gulp, gulp watch. I have to manually run gulp after each change to compile them. Is there something wrong that causing watch to not work as expected?

Gulp 版本CLI 版本 1.4.0本地版本 3.9.1

Gulp Version CLI version 1.4.0 Local version 3.9.1

NPM 4.1.2节点 v7.7.2

NPM 4.1.2 Node v7.7.2

var gulp = require('gulp');

var less = require('gulp-less');

// gulp compile paths

var paths = {
    dist: 'assets/dist'
};

gulp.task('css', function() {
    return gulp.src('assets/less/styles.less')
        .pipe(less({
            compress: true
        }))
        .pipe(gulp.dest(paths.dist))
});

gulp.task('watch', function() {
    gulp.watch('assets/less/*.less', ['css']);  // Watch all the .less files, then run the less task
});

gulp.task('default', ['watch']);

推荐答案

确保您有正确的 .less 文件路径,还需要添加 bowersync.reload 以使其工作.

Make sure you have correct path to the .less files also you need to add bowersync.reload for it to work.

gulp.task('watch', function () {
    gulp.watch('assets/less/*.less', ['css']);
    // init server
    browserSync.init({
        server: {
            proxy: "local.build",
            baseDir: appPath.root
        }
    });

    gulp.watch([appPath.root + '**'], browserSync.reload);
});

gulp.task('default', ['watch']);

这篇关于Gulp 不会看到任何变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆