grunt之easy demo

首先安装grunt-cli

cnpm install -g grunt-cli

接下来创建package.json,内容如下

    {  
      "name": "demo",  
      "file": "zepto",  
      "version": "0.1.0",  
      "description": "demo",  
      "license": "MIT",  
      "devDependencies": {  
        "grunt": "~0.4.1",  
        "grunt-contrib-jshint": "~0.6.3",  
        "grunt-contrib-concat": "~0.5.0",  
        "grunt-contrib-uglify": "~0.2.1",  
        "grunt-contrib-requirejs": "~0.4.1",  
        "grunt-contrib-copy": "~0.4.1",  
        "grunt-contrib-clean": "~0.5.0",  
        "grunt-strip": "~0.2.1"  
      },  
      "dependencies": {  
        "express": "3.x"  
      }  
    } 

 

也可以使用npm init来进行初始化

创建Gruntfile.js,只做合并和压缩

    module.exports = function (grunt) {  
      grunt.initConfig({  
      concat: {  
        options: {  
        },  
        dist: {  
          src: ['src/**/*.js'],//src文件夹下包括子文件夹下的所有文件  
          dest: 'dist/built.js'//合并文件在dist下名为built.js的文件  
        }  
      },  
      uglify: {  
         build: {  
            src: 'dist/built.js',//压缩源文件是之前合并的buildt.js文件  
            dest: 'dist/built.min.js'//压缩文件为built.min.js  
          }  
       }  
    });  
      grunt.loadNpmTasks('grunt-contrib-uglify');  
      grunt.loadNpmTasks('grunt-contrib-concat');  
        
      grunt.registerTask('default', ['concat','uglify']);  
    } 

 

接下来执行cnpm(npm) install,下载好依赖包

接下来执行grunt

 

posted @ 2015-08-20 22:45  Ben Chan  阅读(186)  评论(0编辑  收藏  举报