grunt watch任务不是在看js文件只是说等待

时间:2017-08-24 02:58:49

标签: gruntjs watch gruntfile

我一直在尝试配置这个gruntfile好几天,我已经看过并阅读了多个关于如何设置它的文档。我已经能够设置它,所以我可以通过在bash中输入单个命令来运行单个任务:

grunt uglify 咕噜咕噜咕噜 grunt cssmin

然而,grunt手表似乎没有看到我的任何js文件

所有这些都可以正常工作,但当我尝试在“监视”任务下运行它们时,我的js文件都被忽略了。我的命令行只是读“等待......”。更改我的js文件中的任何内容不会触发更新。我也有运行jshint的toruble,因为它一直告诉我它正在寻找一个字符串等所以我现在禁用该插件。这是我的档案:

module.exports = function (grunt) {

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

    sass: { // Task 
      dist: { // Target        
        files: { // Dictionary of files 
          'assets/css/style.css': 'assets/scss/style.scss'
          // 'destination': 'source' 

        }
      }
    },

    cssmin: {
      options: {
        banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") 
      %> \n*/\n'
      },
      build: {
        files: {
          'assets/css/style.min.css': 'assets/css/style.css'
        }
      }
    },
    uglify: {
      options: {
        banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") 
      %> \n*/\n'
      },
      build: {
        files: {
          'assets/js/magic.min.js': ['assets/js/magic.js', 
           'assets/js/server.js', 'assets/js/script.js']
        }
      }
    },
    // configure jshint to validate js files -------------------------------
    // jshint: {
    //   options: {
    //     reporter: require('jshint-stylish')  

    //   },

    //   // when this task is run, lint the Gruntfile and all js files in 
    src
    //   build: ['Gruntfile.js', 'assets/**/*.js']
    // },


    watch: {

      // for stylesheets, watch css and less files 
      // only run less and cssmin stylesheets: { 
      files: ['assets/**/*.css', 'assets/**/*.less'],
      tasks: ['sass', 'cssmin']
    },

    // for scripts, run jshint and uglify 
    scripts: {
      files: 'assets/**/*.js',
      tasks: 'uglify'
    }
  });
  // Default tasks
  //grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-concurrent');
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.registerTask('default', ['uglify', 'cssmin', 'sass', 'watch']);
};

1 个答案:

答案 0 :(得分:1)

我想你想这样做?

watch: {
    stylesheets: { 
      files: ['assets/**/*.css', 'assets/**/*.less'],
      tasks: ['sass', 'cssmin']
    },

    // for scripts, run jshint and uglify 
    scripts: {
      files: 'assets/**/*.js',
      tasks: 'uglify'
    }
  }