2

I'm trying to concatenate all javascript files inside my controllers directory into one file, located one level higher. This is the code I'm using:

concat: {
  dist: {
    files: {
      '<%= yeoman.app %>/scripts/all.js': [
        '<%= yeoman.app %>/scripts/controllers/{,*/}*.js',
        '<%= yeoman.app %>/scripts/controllers/{,*/}*.js'
      ]
    }
  }
}

It works fine, but I'm forced to manually type grunt concat in console every time I change my javascript files. So I'm trying to get this done with a watcher but can't get it to work. This is my watcher code:

  concat: {
    files: ['<%= yeoman.dist %>/scripts/controllers/*.js'],
    tasks: ['concat']
  },
4

1 回答 1

2

当你想让 watch 监视文件时,你需要输入“grunt watch”。您需要像这样在“Gruntfile.js”中添加监视任务:

watch: {
  concat: {
    files: ['<%= yeoman.dist %>/**/*.js'],
    tasks: "concat"
  }
}

你的 concat 任务仍然需要像你现在一样。

确保你也安装了 grunt-contrib-watch ..

npm install grunt-contrib-watch --save-dev

查看 grunt-contrib-watch 的 github 页面以获取更多信息:https ://github.com/gruntjs/grunt-contrib-watch

于 2013-06-22T00:20:34.507 回答