Gruntfile.js配置全攻略

一般来说,直接使用预置的模板作为配置文件。

module.exports = function(grunt) {
    "use strict";
  grunt.initConfig({
    //插件配置区域
  });
  //加载插件任务,要使用谁就添加谁
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  // 注册任务
  grunt.registerTask('default', ['cssmin', 'imagemin', 'uglify']);
};

grunt.loadNpmTasks()是加载插件任务。其实就是说,你如果要使用哪个插件的功能,请在这部分用这句代码把插件任务添加进去。
grunt.registerTask()是注册任务,默认有一个default。默认的意思就是说,你最后使用的时候,在目录的命令提示符里直接输入grunt便可以执行注册的任务,相当于执行了default这个任务。

使用自定义任务

可以注册更多的任务命令,使用其他的命名。比如

grunt.registerTask('custom', ['cssmin', 'imagemin']);

对应使用的时候,输入:

grunt custom

grunt-contrib-uglify 压缩

grunt-contrib-concat 合并文件

你可能感兴趣的:(Gruntfile.js配置全攻略)