grunt-min

0.1.0 • Public • Published

grunt-min Build Status

使用示例

min任务可以压缩js脚本,css样式,html文档,json数据,jpg、png和gif图片

压缩

grunt.initConfig({
  min: {
    my_target: {
      files: {
        'dest/style.min.css': ['src/style.css'],
        'dest/script.min.js': ['src/input1.js', 'src/input2.js'],
    'dest/index.html': 'src/index.html',
    'dest/data.json': 'src/data.json',
    'dest/t.jpg': 'src/t.jpg'
      }
    }
  }
});

通过except参数可以保留变量名不被混淆

grunt.initConfig({
  uglify: {
    options: {
       except: ['$', 'Backbone']
    },
    my_target: {
      files: {
        'dest/output.min.js': ['src/input.js']
      }
    }
  }
});

使用banner, footer

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  uglify: {
    options: {
      banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
        '<%= grunt.template.today("yyyy-mm-dd") %> */',
      
      footer: '/*end*/'
    },
    my_target: {
      options:{
        //不保留原有js中的注释
        copyright: false
      },
      files: {
        'dest/output.min.js': ['src/input.js']
      }
    }
  }
});

将整个文件夹中的脚本压缩

grunt.initConfig({
  min: {
    my_target: {
      files: [{
          expand: true,
          cwd: 'src/js',
          src: '**/*.js',
          dest: 'dest/js'
      }]
    }
  }
});

datauri任务可以将css文件进行DataURI编码

datauri

grunt.initConfig({
  datauri:{
    my_target: {
      'dest/datauri.css': 'src/style.css'
    }
  }
});

Release History

v0.1.0 2014-1-7


Task submitted by colorhook@gmail.com

Readme

Keywords

none

Package Sidebar

Install

npm i grunt-min

Weekly Downloads

1

Version

0.1.0

License

none

Last publish

Collaborators

  • colorhook