Gruntjs Grunt-start\u server-watch-jshint-html\u minify

Gruntjs Grunt-start\u server-watch-jshint-html\u minify,gruntjs,grunt-contrib-watch,Gruntjs,Grunt Contrib Watch,编写一个grunt文件来验证js 文件使用jshint,缩小html文件,启动web服务器并监视本地web服务器 使用jshint验证js文件 源文件位于“src/js”中 缩小“src”文件夹中的html文件,并将其与同一文件放在“dest/src”文件夹中 名字 html缩小后,设置并运行本地web服务器 运行“监视”任务以监视Web服务器 使用IDE终端安装 插件 仅使用官方grunt插件 为以下所有任务安装必要的grunt命令,并确保命令保存在packages.json中

编写一个grunt文件来验证js 文件使用jshint,缩小html文件,启动web服务器并监视本地web服务器

  • 使用jshint验证js文件

  • 源文件位于“src/js”中

  • 缩小“src”文件夹中的html文件,并将其与同一文件放在“dest/src”文件夹中 名字

  • html缩小后,设置并运行本地web服务器

  • 运行“监视”任务以监视Web服务器

  • 使用IDE终端安装 插件

  • 仅使用官方grunt插件


为以下所有任务安装必要的grunt命令,并确保命令保存在packages.json中,然后尝试以下操作:

module.exports = function(grunt) {
  require('jit-grunt')(grunt);

  grunt.initConfig({
    jshint: {
      files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    },
  htmlmin: {                                     // Task
    dist: {                                      // Target
      options: {                                 // Target options
        removeComments: true,
        collapseWhitespace: true
      },
      files: {                                   // Dictionary of files
        'dest/src/form.html': 'src/form.html',     // 'destination': 'source'
        'dest/src/management.html': 'src/management.html'
      }
    }
  },
    watch: {
      styles: {
        files: ['less/**/*.less'], // which files to watch
        tasks: ['less'],
        options: {
          nospawn: true
        }
      }
    },
connect: {
    server: {
      options: {
        port: 9000,
        base: 'app',
        keepalive: false
      }
    }
  }
  });

  grunt.registerTask('default', ['htmlmin','jshint','connect','watch']);
};