grunt批量压缩js文件

GruntFile.js文件配置如下内容:

module.exports = function(grunt) {  
  
  // Project configuration.  
  grunt.initConfig({  
    pkg: grunt.file.readJSON('package.json'),  
    //压缩js
        uglify: {
            //文件头部输出信息
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */
'
            },
            my_target: {
                files: [
                    {
                        expand: true,
                        //相对路径
                        cwd: 'src/',
                        src: '*.js',
                        dest: 'build/'
                    }
                ]
            }
        },
  });  
  
  // Load the plugin that provides the "uglify" task.  
  grunt.loadNpmTasks('grunt-contrib-uglify');  
  
  // Default task(s).  
  grunt.registerTask('default', ['uglify']);  
  
};  

  

author:Lik
Endeavoring to powerless, struggling to move yourself.
原文地址:https://www.cnblogs.com/likwin/p/7459928.html