Javascript Grunt Smoosher不';我什么也不做
我是格伦特的新手。在这个Gruntfile中,我试图在我的HTML中插入所有CSS和Javascript资源:Javascript Grunt Smoosher不';我什么也不做,javascript,gruntjs,grunt-smoosher,Javascript,Gruntjs,Grunt Smoosher,我是格伦特的新手。在这个Gruntfile中,我试图在我的HTML中插入所有CSS和Javascript资源: module.exports = function ( grunt ) { grunt.initConfig({ smoosher: { files: { 'page1-dist.html': 'page1.html' } } }); grunt.
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中的多任务。基本上,这意味着您需要将设置包装到目标中,即使您只指定了一组选项。查看了这个插件的源代码后,它在底部记录了一个文件的创建,因此只是配置不正确(因为您没有得到预期的输出)。因此,您的GrunFile应该如下所示:
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插件的文档,稍后您会为此感谢自己。:-) 从没听说过“咕噜咕噜”这个词。。它使我大笑起来。。当你大声说出来的时候,听起来很有趣。