grunt压缩js/css

//npm 包管理器

{

  "name": "2016-12-16-grunt",

  "version": "1.0.0",

  "description": "",

  "main": "index.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1"

  },

  "author": "",

  "license": "ISC",

  "devDependencies": {

    "grunt": "^1.0.1",

    "grunt-contrib-cssmin": "^1.0.2",

    "grunt-contrib-uglify": "^2.0.0"

  }

}

//gruntfile.js配置信息

module.exports = function(grunt){

    // 项目配置

    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        uglify: {

            options: {

                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',//添加banner

                 beautify: {

                     //中文ascii化,非常有用!防止中文乱码的神配置

                     ascii_only: true

                 }

            },

            buildall: {//按原文件结构压缩js文件夹内所有JS文件

                files: [{

                    expand:true,

                    cwd:'origin_js',//js目录下

                    src:'**/*.js',//所有js文件

                    dest: 'js'//输出到此目录下

                }]

            }

        },

        cssmin: {

             //文件头部输出信息

             options: {

                 banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',

                //美化代码

                 beautify: {

                     //中文ascii化,非常有用!防止中文乱码的神配置

                     ascii_only: true

                 }

             },

             my_target: {

                 files: [

                     {

                         expand: true,

                         //相对路径

                         cwd: 'origin_stylesheets/',

                         src: '**/*.css',

                         dest: 'stylesheets'

                     }

                 ]

             }

         }

     });

    // 加载提供"uglify"任务的插件

    grunt.loadNpmTasks('grunt-contrib-uglify');

    grunt.loadNpmTasks('grunt-contrib-cssmin');

    // 默认任务

    grunt.registerTask('default', ['uglify', 'cssmin']);

    // grunt.registerTask('default', ['uglify:buildall','cssmin']);

    // grunt.registerTask('minall', ['uglify:buildalls','cssmin']);

}

猜你喜欢

转载自minemine-flying.iteye.com/blog/2345386