Grunt观察者为javascript concat

时间:2013-06-21 20:29:46

标签: javascript gruntjs concat

我正在尝试将控制器目录中的所有javascript文件连接到一个文件,位于更高的一级。这是我正在使用的代码:

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

它工作正常,但每次更改我的javascript文件时,我都被迫在控制台中手动输入grunt concat。所以我试图用观察者完成这项工作,但无法让它发挥作用。这是我的观察者代码:

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

1 个答案:

答案 0 :(得分:2)

当您想让手表监控文件时,您需要输入“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