[英]Example on how to have two Grunt configurations, one with concat and one without
So, I discovered the amazing power of grunt, and I like. 因此,我发现了咕unt的惊人力量,而且我喜欢。 So after concatenating many js files and uglifying them I'm saving a lot of bandwidth... great.
因此,在串联许多js文件并将其丑化之后,我节省了大量带宽...太好了。 Problem is that when developing I'd like to have them standalone (so it's easier to debug).
问题是,在开发时,我想让它们独立(这样更容易调试)。 Then when I'm ready for production I'd like to put them all in a single minified file.
然后,当我准备进行生产时,我想将它们全部放在一个缩小的文件中。
I can think of many ways to do this, but, is there a best practice or some plugin? 我可以想到许多方法来做到这一点,但是,是否有最佳实践或某些插件?
Use targets: 使用目标:
grunt.initConfig({
concat: {
dev: {
files: [
{ src: ['src/foo/*.js'], dest: 'dist/foo.js' },
{ src: ['src/bar/*.js'], dest: 'dist/bar.js' },
],
},
prod: {
src: ['src/**/*.js'], dest: 'dist/all.js',
},
},
uglify: {
prod: {
src: 'dist/all.js', dest: 'dist/all.min.js',
},
}
});
grunt.registerTask('dev', ['concat:dev']);
grunt.registerTask('prod', ['concat:prod', 'uglify']);
Then run grunt dev
when you want a development build or grunt prod
when you want a production build. 然后,如果您要开发,请运行
grunt dev
,如果要grunt prod
,请运行grunt dev
grunt prod
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.