【问题标题】:Grunt - start_server-watch-jshint-html_minify咕噜声 - start_server-watch-jshint-html_minify
【发布时间】:2021-07-28 05:20:19
【问题描述】:

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

  • 使用 jshint 验证 js 文件。

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

  • 压缩“src”文件夹中的html文件,并将其放在“dest/src”文件夹中,文件相同 名字。

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

  • 运行监视任务来监视网络服务器。

  • 使用IDE终端安装 插件。

  • 仅使用官方的 grunt 插件。

【问题讨论】:

    标签: gruntjs grunt-contrib-watch


    【解决方案1】:

    为以下所有任务安装必要的 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']);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      相关资源
      最近更新 更多