简体   繁体   English

如何具有两种Grunt配置的示例,一种带有concat,另一种不带concat

[英]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.

相关问题 如何使用此数据将两个数组合二为一? JS - How to concat two array in one with this data? JS 用咕unt声将功能的多个部分合并并合并到一个文件中 - Concat and uglify multiple parts of a function into one file with grunt 如何使用我自己的选项配置concat和uglify与grunt-usemin - How to use my own option configurations for concat and uglify with grunt-usemin 如何将两个被调用的端点连接到一个字符串并在控制台中打印它 - How to concat two called endpoints to one string and print it in console 如何连接两个字段并检查新字段是否在续集中包含 substring? - How to concat two fields and check if the new one includes a substring in sequelize? 在一台机器上安装两个不同版本的grunt - Installing two different versions of grunt on one machine 如何在一个页面上有两个这样的音频播放器,而又不单击另一个播放器或显示隐藏播放列表 - How can i have two of these audio players on one page, without clicking on one and the other one play or show hide playlist 如何在一个URL中有两种类型的参数,其中一种以“#”开头,​​另一种以“&”开头,而不替换另一种? - How can I have two types of parameters in one URL, where one starts with “#” and the other one starts with “&” and without replacing the other? 如果有匹配的元素,如何比较 2 个单独的对象/数组是否有一个相同的元素并将 2 个对象连接到一个数组中? Javascript - How to compare if, 2 separate Objects/Array have one same element and concat 2 objects into one array, if there is matching element? Javascript Concat将两个WinJS.Binding.List合并为一个 - Concat two WinJS.Binding.List into one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM