2014-02-28 23 views
1

我想爲我的grunt工作流程使用Grunt Bake。這是我的grunt.js設置:使用Grunt Bake觀看多個文件而不一次編譯全部

grunt.initConfig({ 

    bake: { 
     build: { 
      files: { 
       'dev/foo.html': 'public/foo.html', 
       'dev/bar.html': 'public/bar.html', 
       'dev/foo2.html': 'public/foo2.html' 
       // ... 
      } 
     } 
    }, 

    watch: { 
     bake: { 
      files: ['dev/*.html'], 
      tasks: ['bake:build'] 
     } 
    } 

}); 

我的問題:如果我改變一個文件所有文件將被編譯。我可以創建爲每個文件手錶聽衆解決這個問題,但這似乎不是一個聰明的解決方案:

grunt.initConfig({ 

    bake: { 
     foo: { 
      files: { 
       'dev/foo.html': 'public/foo.html' 
      } 
     }, 
     bar: { 
      files: { 
       'dev/bar.html': 'public/bar.html' 
      } 
     }, 
     foo2: { 
      files: { 
       'dev/foo2.html': 'public/foo2.html' 
      } 
     } 
     // ... 
    }, 

    watch: { 
     foo1: { 
      files: ['dev/foo.html'], 
      tasks: ['bake:foo'] 
     }, 
     bar: { 
      files: ['dev/bar.html'], 
      tasks: ['bake:bar'] 
     }, 
     foo2: { 
      files: ['dev/foo2.html'], 
      tasks: ['bake:foo2'] 
     } 
    } 

}); 

試想一下,有20多個不同的HTML文件...所以這不是我的選擇。任何其他解決方案呢?

回答

2

好吧,明白了!

恰好有這樣做的一個newer task

grunt.initConfig({ 

    bake: { 
     build: { 
      files: { 
       'dev/foo.html': 'public/foo.html', 
       'dev/bar.html': 'public/bar.html', 
       'dev/foo2.html': 'public/foo2.html' 
       // ... 
      } 
     } 
    }, 

    watch: { 
     bake: { 
      files: ['dev/*.html'], 
      tasks: ['newer:bake:build'] 
     } 
    } 

}); 
+0

如果你能回答自己的問題,我認爲你可以將其標記爲已解決自己是否能解決這個問題。 (它明顯在你的情況下)。 PS:使用咕嚕咕嚕的歡呼聲。希望這是有幫助的。 :) – Mathias

相關問題