标签: grunt-contrib-watch

Grunt watch:仅上传已更改的文件

有关

我能够使用grunt-ssh为我的开发服务器设置一个Grunt任务到SFTP文件:

sftp: {
    dev: {
        files: {
            './': ['**','!{node_modules,artifacts,sql,logs}/**'],
        },
        options: {
            path: '/path/to/project',
            privateKey: grunt.file.read(process.env.HOME+'/.ssh/id_rsa'),
            host: '111.111.111.111',
            port: 22,
            username: 'marksthebest',
        }
    }
},
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,这会上传所有内容.有数千个文件.每次修改文件时,我都没有时间等待他们逐个上传.

一旦我更改了文件,如何设置手表才能上传我已更改的文件?

(好奇的是,服务器是本地网络上的虚拟机.它运行在不同的操作系统上,设置与我的本地机器的设置更相似.如果我能正常工作,上传应该是快速的)

ssh gruntjs grunt-contrib-watch

9
推荐指数
3
解决办法
4992
查看次数

Grunt watch:只编译一个文件而不是全部

我有咕噜咕噜的设置将我的所有咖啡文件编译成javascript并使用dynamic_mappings维护所有文件夹结构,效果很好.

coffee: {
  dynamic_mappings: {
    files: [{
      expand: true,
      cwd: 'assets/scripts/src/',
      src: '**/*.coffee',
      dest: 'assets/scripts/dest/',
      ext: '.js'
    }]
  }
}
Run Code Online (Sandbox Code Playgroud)

我想要做的是使用watch来编译任何已更改的咖啡文件并仍然保持文件夹结构.这对于此监视任务使用上述任务:

watch: {
  coffeescript: {
    files: 'assets/scripts/src/**/*.coffee',
    tasks: ['coffee:dynamic_mappings']
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是,当一个文件发生变化时,它会将整个咖啡目录再次编译成Javascript,如果它只编译改为Javascript的单个咖啡文件,那将会很棒.这在Grunt中是否自然可行,或者这是一个自定义功能.这里的关键是它必须保持文件夹结构,否则它会很容易.

我们在工作中有自定义监视脚本,我试图在Grunt上销售它们,但是需要这个功能来完成它.

node.js coffeescript gruntjs grunt-contrib-watch

8
推荐指数
1
解决办法
3130
查看次数

如何有条件地编译(使用Grunt)只更改了包含模板的jade文件

使用grunt-contrib-watch建议仅在此处编译已更改文件的版本:https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed

var changedFiles = Object.create(null);

var onChange = grunt.util._.debounce(function() {
grunt.config('jshint.all.src', Object.keys(changedFiles));
   changedFiles = Object.create(null);
}, 200);

grunt.event.on('watch', function(action, filepath) {
   changedFiles[filepath] = action;
   onChange();
});
Run Code Online (Sandbox Code Playgroud)

这工作正常(再次我在这里写的变体:https://gist.github.com/pgilad/6897875)

问题include在Jade模板中使用时,意味着你要包含其他Jade模板以构建完整的html文件.

使用单数解决方案进行编译不起作用,因为如果.jade正在使用include current_working_jade.jade文件是嵌入式的- 包含文件将不会被重新编译.

除了jade从头开始编译所有文件之外,还有其他解决方法吗?每次有大约60个大型玉文件要编译时,这会导致问题.

我能想到的唯一可能的解决方案是在外部或使用目录映射jade模板依赖项,但我不知道有哪些工具/插件可以做到这一点......

javascript compilation gruntjs grunt-contrib-watch pug

8
推荐指数
1
解决办法
1441
查看次数

Grunt:看多个文件,只编译改变 - livereload break?

我是Grunt和Javascript/Coffeescript的新手.

我们在一个包含数百个.coffee文件的大型项目中使用Grunt.由于Grunt编译了所有的咖啡文件(尽管只有一个文件已经更改),我最初的问题是如何让Grunt只编译一个更改的文件.使用stackoverflow我能够回答这个问题,谢谢大家:)

但现在似乎已实施的解决方案打破了实时重载.当我从"grunt服务器"开始并在浏览器中显示我的页面时,一切看起来都很好.然后我更改一个.coffee文件并保存.文件被编译(我已检查),但我的浏览器从未被重新加载.只有当我手动重新加载浏览器时,才会显示新修改的代码.

所以问题是:为什么livereload不再有效?

我不知道这是否重要,但Gruntfile是在旧版本中使用yeoman创建的(使用grunt-regarde).我使用grunt-contrib-watch和buildin livereload将package.json和Gruntfile更新为更新的规范.没有grunt.event.on一切正常.

来源(部分):

grunt.initConfig({

    watch: {
            coffee: {
                files: ['<%= yeoman.app %>/coffeescripts/**/*.coffee'],
                tasks: ['coffee:app'],
                options: {
                    nospawn: true
                },
            },
            compass: {
                files: ['<%= yeoman.app %>/styles/**/*.{scss,sass}'],
                tasks: ['compass']
            },
            templates: {
                files: ['<%= yeoman.app %>/templates/**/*.tpl'],
                tasks: ['handlebars']
            },
            livereload: {
                options: {
                    livereload: LIVERELOAD_PORT
                },
                files: [
                    '<%= yeoman.app %>/*.html',
                    '<%= yeoman.tmp %>/styles/**/*.css',
                    '<%= yeoman.tmp %>/scripts/**/*.js',
                    '<%= yeoman.tmp %>/spec/**/*.js',
                    '<%= yeoman.app %>/img/{,*/}*.{png,jpg,jpeg,webp}',
                ]
            }
        },
        coffee: {
            app: {
                expand: true,
                cwd: …
Run Code Online (Sandbox Code Playgroud)

javascript coffeescript gruntjs livereload grunt-contrib-watch

7
推荐指数
1
解决办法
4203
查看次数

运行除一个之外的所有Grunt SubTasks

我有一堆用于咕噜咕噜的手表(例如grunt手表:款式,咕噜咕噜的手表:精灵等).然后运行许多其他任务grunt watch.我想排除一项任务.有没有办法指定?基本上运行所有grunt watch子任务除外grunt watch:dist.

我知道我可以创建另一个任务并且只指定我真正感兴趣的子任务,但是,如果我稍后添加另一个子任务,这意味着现在我要添加它,所以我宁愿不这样做.

谢谢

gruntjs grunt-contrib-watch

7
推荐指数
1
解决办法
2557
查看次数

grunt-notify:成功时不触发

我试图用grunt-contrib-lessgrunt-contrib-watch设置grunt-notify.一般情况下,这种方法运行良好,但是当grunt-less成功执行时,我无法通知grunt-notify通知我.

如果有人对如何设置或调试有任何见解,很高兴有任何输入.


完整信息:

我已经设置了grunt-notify,只要少用手表运行就会触发.当较少的任务失败时,这很有效.给我一个很棒的弹出错误:

图片

作为参考,这是控制台输出:

图片

如果不太成功,我没有收到任何通知.我想收到通知,但无法弄清楚如何启用此功能.

当成功较少时,这是控制台输出:

图片

这是我使用的GruntFile:

module.exports = function(grunt) {

    grunt.initConfig({

        less: {
            development: {
                options: {
                    compress: true
                },
                files: {
                    "FILE.css": "FILE2.less"
                }
            }
        },

        watch: {
            less: {
                files: '**/*.less',
                tasks: ['less', 'notify_hooks']
            }
        },


        notify_hooks: {
            options: {
                message: "MESSAGE"
            }

        }


    });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-notify');

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

};
Run Code Online (Sandbox Code Playgroud)

关于Github的原始问题

javascript less gruntjs grunt-contrib-watch grunt-notify

7
推荐指数
2
解决办法
2241
查看次数

ctrl-c [SIGINT]在使用grunt-shell时不使用Grunt

如果我使用Grunt Task Runner和grunt-shell,我无法使用ctrl-c [SIGINT]退出grunt.

grunt.registerTask('serve', [
  'less',
  'autoprefixer',
  'shell:hologram', // grunt-shell task
  'connect:livereload',
  'watch'
]);
Run Code Online (Sandbox Code Playgroud)

以下是shell的配置方式:

grunt.initConfig({

...

  shell: {
    options: {
      failOnError: false
    },
    hologram: {
      command: 'bundle exec hologram'
    },
  },

...

}
Run Code Online (Sandbox Code Playgroud)

gruntjs grunt-contrib-watch grunt-shell

7
推荐指数
1
解决办法
393
查看次数

当使用grunt-contrib-watch时,grunt-autoprefixer无休止地循环

我只是在学习Grunt.我将使用罗盘进行垂直节奏和图像精灵生成,并使用autoprefixer为css3样式添加前缀.

这是我的Gruntfile.js.

module.exports = function(grunt) {
  var globalConfig = {
    sassDir: 'sass',
    cssDir: 'css'
  };

  require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  // Project configuration.
  grunt.initConfig({
    globalConfig: globalConfig,
    pkg: grunt.file.readJSON('package.json'),
    compass: {
      dev: {
        options: {
          sassDir: '<%= globalConfig.sassDir %>',
          cssDir: '<%= globalConfig.cssDir %>'
        }
      }
    },
    autoprefixer: {
      dev: {
        options: {
          browsers: ['last 2 versions']
        },
        src: '<%= globalConfig.cssDir %>/style.css',
        dest: '<%= globalConfig.cssDir %>/style.css'
      }
    },
    watch: {
      compass: {
        files: ['<%= globalConfig.sassDir %>/**/*.scss'],
        tasks: ['compass:dev'],
      },
      autoprefixer: {
        files: …
Run Code Online (Sandbox Code Playgroud)

gruntjs grunt-contrib-watch

6
推荐指数
1
解决办法
1835
查看次数

Grunt配置监视和业力:单个任务中的单位

目前我遵循Gruntfile配置,有两个独立的任务,它完美无缺:

grunt.registerTask('server', [
    'connect',
    'jshint',
    'less:dev',
    'watch'
]);

grunt.registerTask('test', [
    'karma:unit'
]);
Run Code Online (Sandbox Code Playgroud)

我想做一个涵盖两件事并登录到一个终端窗口的任务.就像是:

grunt.registerTask('dev', [
    'connect',
    'jshint',
    'less:dev',
    'karma:unit',
    'watch'
]);
Run Code Online (Sandbox Code Playgroud)

问题在于业力和手表不能一起工作.我试图把karma:unit:runwatch配置和它的作品,但每个文件都加载变化人缘配置.这件事我不喜欢:

Running "karma:unit:run" (karma) task
[2014-05-25 01:40:24.466] [DEBUG] config - Loading config /Users/.../test/karma.config.js
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.011 secs / 0.012 secs)
Run Code Online (Sandbox Code Playgroud)

是否有可能解决此问题或更好地单独运行这些任务?

javascript gruntjs karma-runner grunt-contrib-watch

6
推荐指数
1
解决办法
2039
查看次数

当我运行Grunt时,我收到以下消息:找不到本地npm模块"grunt-contrib-copy".它安装了吗?

我一直在尝试安装Grunt.当我运行grunt时,我收到以下消息和警告列表:

Local Npm module "grunt-contrib-copy" not found.  Is it installed?
Local Npm module "grunt-contrib-uglify" not found.  Is it installed?
Local Npm module "grunt-contrib-jshint" not found.  Is it installed?
Local Npm module "grunt-contrib-less" not found.  Is it installed?
Local Npm module "grunt-contrib-clean" not found.  Is it installed?
Local Npm module "grunt-contrib-watch" not found.  Is it installed?
Local Npm module "grunt-contrib-concurrent" not found.  Is it installed?
Local Npm module "grunt-contrib-nodemon" not found.  Is it installed?
Local Npm module "grunt-contrib-newer" not found.  Is …
Run Code Online (Sandbox Code Playgroud)

node.js npm grunt-contrib-watch grunt-contrib-copy grunt-contrib-uglify

6
推荐指数
1
解决办法
1万
查看次数