我使用Grunt.js来连接/缩小文件 - 但是想使用1个常用的grunt.js文件来连接/压缩不同网站的多个目录中的文件。最好的方法是什么?
我希望我可以设置两个不同的任务:
//ATG INTL US (excluding VIR)
concat1: {
dist: {
src: ['<banner:meta.banner>', '../js/plugins/jquery.tools.min.js','../js/plugins/jquery.validate.min.js','../js/plugins/jcarousellite_1.0.1.min.js','../js/plugins/jquery.jcarousel.min.js','../js/plugins/jquery.qtip-1.0.0-rc3.min.js','../js/plugins/jquery.cookie.js','../js/plugins/jquery.fancybox-1.3.4.min.js','../js/lib/modernizr/modernizr.custom.39125.js','../js/plugins/jquery.select2.min.js'], dest: '../js/common/plugins.js'
}
},
// ATG INTL US (VIR ONLY)
concat2: {
dist: {
src: ['<banner:meta.banner>', '../js/plugins/jquery.tools.min.js','../js/plugins/jquery.validate.min.js','../js/plugins/jcarousellite_1.0.1.min.js','../js/plugins/jquery.jcarousel.min.js','../js/plugins/jquery.qtip-1.0.0-rc3.min.js','../js/plugins/jquery.cookie.js','../js/plugins/jquery.fancybox-1.3.4.min.js','../js/lib/modernizr/modernizr.custom.39125.js','../js/plugins/jquery.select2.min.js','../include/js/plugins/jquery-ui.selectmenu.js'], dest: '../js/common/plugins.js'
}
},
然后在我想要运行它时注册不同的任务:
grunt.registerTask('default', 'lint qunit mincss concat1 min');
但这似乎不起作用,我听说过但不确定这是否有效。有什么建议吗?
答案 0 :(得分:1)
我明白了!
我可以设置不同的目录:
concat: {
//ATG INTL US (excluding VIR)
atgintlus: {
src: ['<banner:meta.banner>', '../js/plugins/jquery.tools.min.js','../js/plugins/jquery.validate.min.js','../js/plugins/jcarousellite_1.0.1.min.js','../js/plugins/jquery.jcarousel.min.js','../js/plugins/jquery.qtip-1.0.0-rc3.min.js','../js/plugins/jquery.cookie.js','../js/plugins/jquery.fancybox-1.3.4.min.js','../js/lib/modernizr/modernizr.custom.39125.js','../js/plugins/jquery.select2.min.js'], dest: '../js/common/plugins.js'
},
// ATG INTL US (VIR ONLY)
atgintlvir: {
src: ['<banner:meta.banner>', '../js/plugins/jquery.tools.min.js','../js/plugins/jquery.validate.min.js','../js/plugins/jcarousellite_1.0.1.min.js','../js/plugins/jquery.jcarousel.min.js','../js/plugins/jquery.qtip-1.0.0-rc3.min.js','../js/plugins/jquery.cookie.js','../js/plugins/jquery.fancybox-1.3.4.min.js','../js/lib/modernizr/modernizr.custom.39125.js','../js/plugins/jquery.select2.min.js','../include/js/plugins/jquery-ui.selectmenu.js'], dest: '../js/common/plugins.js'
}
},
然后注册不同的任务:
// ATG INTL US task.
// Run in Command line using Grunt atgintlus
grunt.registerTask('atgintlus', ['lint','mincss','concat:atgintlus', 'min:atgintlus']);
// VIR US task.
// Run in Command line using Grunt atgintlvir
grunt.registerTask('atgintlvir', ['lint','mincss','concat:atgintlvir', 'min:atgintlvir']);
像梦一样工作!
答案 1 :(得分:0)
是的,所以你所做的就是创建一个“多任务”(一个有多个目标的任务)。看起来你已经开始了,但你可能想看看我在grunt.js上制作的series of vids可能会帮助你进一步了解grunt.js,这里是tasks上的那个。