2013-03-27 66 views
26

我試圖讓咕嚕工作做些事情。我的項目是這樣的:咕嚕,少,和文件觀看

/app 
    /assets 
     /components 
     /stylesheets 
      /less 
       /file1.less 
       /file2.less 
       /file3.less 
       /importAll.less 
      /css 

我希望它這樣,當file1file2file3保存在importAll.less文件編譯成CSS和投入/css/style.css。這是我得到的。

less: { 
    development: { 
     options: { 
      paths: ["./assets/stylesheets/less"], 
      yuicompress: true 
     }, 
     files: { 
      "./assets/stylesheets/css/style.css": "./assets/stylesheets/less/importAll.less" 
     } 
    } 
} 

我不知道如何讓文件觀察器工作。

回答

54

我知道它與以下工作!

module.exports = function(grunt) { 
    grunt.initConfig({ 
     less: { 
      development: { 
       options: { 
        paths: ["./assets/stylesheets/less"], 
        yuicompress: true 
       }, 
       files: { 
        "./assets/stylesheets/css/style.css": "./assets/stylesheets/less/style.less" 
       } 
      } 
     }, 
     watch: { 
      files: "./assets/stylesheets/less/*", 
      tasks: ["less"] 
     } 
    }); 
    grunt.loadNpmTasks('grunt-contrib-less'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
}; 
+13

對於像我這樣的新手,它可能會幫助提的是,只運行'grunt'您需要定義像'grunt.registerTask(「默認」,「手錶」)的默認任務;'僅供參考[ docs](http://gruntjs.com/api/grunt.task#grunt.task.registertask) – 2013-12-21 00:35:05

+1

如何在'less {}'塊中執行'less:development'時知道如何執行多個任務? – 2014-06-25 08:05:58

+2

@WillshawMedia只運行「開發」部分,使用'grunt less:development'。 'grunt less'將全部運行在'less'之下 – tivnet 2014-08-20 19:55:49