[英]Grunt Smoosher doesn't do anything
我是Grunt的新手。 在此Gruntfile中使用smoosher ,我試圖在HTML中插入所有CSS和Javascript資源:
module.exports = function ( grunt ) {
grunt.initConfig({
smoosher: {
files: {
'page1-dist.html': 'page1.html'
}
}
});
grunt.loadNpmTasks( 'grunt-html-smoosher' );
grunt.registerTask( 'default', [ 'smoosher' ] );
};
但是它什么也沒做。 它不會創建任何page1-dist.html
文件。 這是運行grunt
時獲得的唯一輸出:
Running "smoosher:files" (smoosher) task
Done, without errors.
知道有什么問題嗎?
問題在於grunt-html-smoosher
在Grunt中被稱為multitask
。 基本上,這意味着即使您僅指定一組選項,也需要將設置包裝在目標中。 在查看了此插件的源代碼之后,它在底部記錄了已創建文件的情況,因此僅是錯誤的配置(因為未獲得預期的輸出)。 因此,您的Gruntfile應該看起來像這樣:
module.exports = function ( grunt ) {
grunt.initConfig({
smoosher: {
dist: {
files: {
'page1-dist.html': 'page1.html'
}
}
}
});
grunt.loadNpmTasks( 'grunt-html-smoosher' );
grunt.registerTask( 'default', [ 'smoosher' ] );
};
如果願意,可以用其他東西代替dist
。
許多Grunt任務都遵循此模式,如果您在特定插件中根據要影響的文件使用不同的選項,這很有用,但是如果插件的行為不符合您的期望,則應牢記這一點。 務必確保閱讀Grunt插件的文檔,以后再感謝您。 :-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.