Gruntjs 当contrib copy或tinyimg在目标(!)中生成更改时,livereload已激发,但不会重新加载页面

Gruntjs 当contrib copy或tinyimg在目标(!)中生成更改时,livereload已激发,但不会重新加载页面,gruntjs,livereload,Gruntjs,Livereload,这是我的问题 根据下面的gruntfile.js,所有提到的路径都被很好地监视(如grunt--verbose-v所示)。每当我更改文件时,Livereload都会激发(至少--verbose显示Livereload激发)。但是,只有在我更改了/development/index.html(以升华文本形式)或/less/mainpage.less(使用contrib-less)的情况下,页面才会被实时重新加载 如果我更改了development/img//*或/test//*中的任何内容,liv

这是我的问题

根据下面的gruntfile.js,所有提到的路径都被很好地监视(如grunt--verbose-v所示)。每当我更改文件时,Livereload都会激发(至少--verbose显示Livereload激发)。但是,只有在我更改了/development/index.html(以升华文本形式)或/less/mainpage.less(使用contrib-less)的情况下,页面才会被实时重新加载

如果我更改了development/img//*或/test//*中的任何内容,livereload将启动,但不会重新加载我的页面

如果有人能帮助我,我将不胜感激

以下是我的文件夹结构:

这是我的Grunfile.js:

module.exports = function(grunt) {
grunt.initConfig({

watch: {
    livereload: {
        files: ['development/*.html', "test/**/*", "development/img/**/*"],
        options: {
            livereload: true,
            spawn: false
        }
    },

    // watch tasks start here
    scripts: {
        files: ['development/js/**/*.js'],
        tasks: ['concat']
    },
    html: {
        files: ['development/*.html'],
        tasks: ['copy:html']
    },
    less_compile: {
        files: ['development/a_source/less/**/*.less'],
        tasks: ['less', "stripCssComments"]
    },
    images: {
        files: ['development/img/**/*'],
        tasks: ['tinyimg']
    }
},

// runs local server for livereload
connect: {
    sever: {
        options: {
            hostname: 'localhost',
            port: 3000,
            base: 'test/',
            livereload: true
        }
    }
},

// *** *.html, *.img copy task here
copy: {
    html: {
        expand: true,
        cwd: 'development',
        src: '*.html',
        dest: 'test/',
    }
},

// *** LESS tasks here
less: {
    compile: {
        options: {
            paths: ["development/b_components/less/"]
        },
        files: {
            "temp/css/style.css": "development/a_source/less/style.less"
        }
    }
}, // compiles less and put compiled version into /temp/css/style.test

stripCssComments: {
    dist: {
        files: {
            'test/css/style.css': 'temp/css/style.css'
        }
    }
}, // strips comments from /temp/css/style.css and copies it to /test/

// minify images
tinyimg: {
    dynamic: {
        files: [{
            expand: true, // Enable dynamic expansion
            cwd: 'development/img/', // Src matches are relative to this path
            src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
            dest: 'test/img/' // Destination path prefix
        }]
    }
}

}); //initConfig

grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-strip-css-comments');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-tinyimg');

grunt.registerTask('default', ["connect", "watch"]);

}; //wrapper function
试试这个

livereload:{
    options:{
      livereload:'<%= connect.options.livereload %>'
    },
    files:[
      'app/{,*/}*.html',
      'app/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
    ]
  }
livereload:{
选项:{
livereload:'
},
档案:[
'app/{,*/}*.html',
'app/images/{,*/}{png,jpg,jpeg,gif,webp,svg}'
]
}
如果您在“图像”文件夹中进行了更改,则应重新加载。(根据您的结构自定义URL。)

试试这个

livereload:{
    options:{
      livereload:'<%= connect.options.livereload %>'
    },
    files:[
      'app/{,*/}*.html',
      'app/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
    ]
  }
livereload:{
选项:{
livereload:'
},
档案:[
'app/{,*/}*.html',
'app/images/{,*/}{png,jpg,jpeg,gif,webp,svg}'
]
}

如果您在“图像”文件夹中进行了更改,则应重新加载。(根据您的结构自定义URL。)

确定。我只是想在我解决了所有的问题后结束

我达到了以下可接受的工作设置:
-如上所述:Grunt仅充当“文件”工作者,执行所有编译/编译/复制等操作。 工作。
-浏览器同步是我的本地服务器(还有一系列其他重要功能)和快速livereload工具,可以进行额外的同步 几个打开的测试窗口()。

-Divy:对我的工作流程进行了很好的补充,能够在桌面上动态安排窗口()。

好的。我只是想在我解决了所有的问题后结束

我达到了以下可接受的工作设置:
-如上所述:Grunt仅充当“文件”工作者,执行所有编译/编译/复制等操作。 工作。
-浏览器同步是我的本地服务器(还有一系列其他重要功能)和快速livereload工具,可以进行额外的同步 几个打开的测试窗口()。
-Divy:对我的工作流程进行了很好的补充,能够在桌面上动态安排窗口()。

更新: 在我切换到Gulp+Browsersync后不久。我非常满意。Gulp的工作速度大约是Browsersync的10倍,而且Browsersync非常流畅方便

下面是我的gulpfile.js示例,只是为了演示这对搭档为我管理的任务:

var gulp=require(“gulp”),
gutil=需要(“咕噜咕噜咕噜”),
less=需要('GLUP-less'),
concat=require('gulp-concat'),
browserify=require('gulp-browserify'),
browserSync=require('browser-sync')。create(),
gulpcopy=require('gulp-copy'),
更新=需要('gulp-newer'),
imagemin=require('gulp-imagemin'),
autoprefixer=require('gulp-autoprefixer'),
uglifyjs=require('gulp-uglify'),
cleanCSS=require('gulp-clean-css'),
uglifycss=需要('gulp-uglifycss'),
htmlmin=require('gulp-htmlmin'),
htmlhint=require(“吞咽htmlhint”),
htmlv=require('gulp-html-validator'),
validatecss=require('gulp-w3c-css'),
sourcemaps=require('gulp-sourcemaps');
var lessMain=[“src/styles/less/styles.less”],
lessSources=[“src/styles/less/*.less”,“src/styles/**.css”],
jsSources=“src/js/*.js”,
jsonSources=[“src/js/*.json”],
htmlSources=[“src/html/*.html”],
imgSources=[“z_设计/图像/处理/****”],
imgDest=[“public/img/****”],
cssTemp=[“src/temp/css/styles.css”],
srcjQuery=“node\u modules/jquery/dist/jquery.min.js”,
srcmastache=“node_modules/mustache/mustache.min.js”;
任务(“消息”,函数(){
gutil.log(“=============================================================”);
});
//少编
任务(“少编译”,函数(){
大口src(莱斯曼)
//打开/关闭源地图
.pipe(sourcemaps.init())
.管道(减去)
.on(“错误”,gutil.log))
//打开/关闭源地图
.pipe(sourcemaps.write())
//将.dest(“文件夹”)更改为“public/css”
//不进行自动刷新
//或“src/temp/css/”以打开autoprefix
.管道(大口目的地(“公共/css”))
});
//准备并复制js文件
gulp.task(“js”,function(){
src([srcjQuery,srcmastache,jsSources])
.pipe(concat(“script.js”))
.pipe(gulp.dest(“public/js/”))
});
//.pipe(browserify())
//{bundleExternal:false}
//复制JSON文件
task(“copyjson”,function()){
gulp.src(jsonSources)
.pipe(较新的(“public/js/”)
.管道(gulpcopy(“public/js/”){
前缀:2
}))
});
//复制html文件
gulp.task(“copyhtml”,function()){
gulp.src(htmlSources)
.pipe(较新的(“public/”)
.管道(gulpcopy(“公共/”{
前缀:2
}))
});
//---缩小和压缩图像:2个任务-自动和手动
//缩小和复制图像-手动任务
任务(“img ondemand”,function()){
gulp.src(“z_设计/图像/未处理/****)
.pipe(较新的(“public/img/”)
.管道(最小值)({
进步的:是的
}))
.pipe(gulp.dest('z_design/images/processed/'))
});
//缩小和复制图像-自动任务
gulp.task(“processimages”,function()){
gulp.src(IMG资源)
.pipe(较新的(“public/img/”)
.管道(最小值)({
进步的:是的
}))
.pipe(大口目的地('public/img/'))
});
//---结束
//强制重新装载
任务(“重新加载”,函数(){
重新加载();
});
//自动刷新器
gulp.task(“autoprefix”,function()){
大口src(cssTemp)
.管道(自动刷新器)({
浏览器:['last 3 versions','safari 5','ie 8','ie 9','ie 10','ie11','opera 12.1','ios 6','android 4'],
瀑布:错
}))
.pipe(gulp.dest(“public/css/”))