grunt watch 没有编译所有 sass 文件尽管是 "watched"

grunt watch not compiling all sass files despite being "watched"

目前我有 2 个问题似乎找不到答案。 当我保存我的主 styles.scss 时,sass 编译正常,但当我保存 _globals.scss 或任何其他 scss 文件时,grunt watch 似乎检测到更改,但它没有编译!我需要做什么来纠正这个问题?

我的第二个问题是当我在 scss 文件夹中的目录中有一个 scss 文件时,例如:pages/_gallery.scss(正在主 styles.scss 中导入),grunt watch 没有看不到,我知道这可能是因为我的 cwd 路径,但如何使它更通用?

这是我的 Gruntfile.js:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({

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

    watch: {
      scripts: {
        files: ['public/resources/site/js/*.js'],
        tasks: ['newer:jshint', 'newer:uglify:dist'],
        options: {
          spawn: false,
          livereload: true,
        },
      },
      sass: {
        files: ['public/resources/site/scss/*.scss'],
        tasks: ['newer:sass:app'],
        options: {
          livereload: true
        }
      },
      php:{
          files: ['public/index.php'],
          options: {
            livereload: true
          }
      }
    },
    sass: {
      app: {
        files: [{
          expand: true,
          cwd: 'public/resources/site/scss/',
          src: ['*.scss'],
          dest: 'public/resources/site/css/',
          ext: '.css'
        }]
      },
      options: {
        sourceMap: true,
        outputStyle: 'compressed'
      }
    },
    uglify: {
      dist: {
        options: {
          sourceMap: true,
          mangle: true
        },
        files: [{
          expand: true,
          cwd: 'public/resources/site/js/',
          src: ['*.js'],
          dest: 'public/resources/site/js/',
          ext: '.min.js'
        }]
      }
    },
    jshint: {
      options: {
        force: true
      },
      files: [
          'public/resources/site/js/*.js',
          '!public/resources/site/js/*.min.js'
      ]
    },
    notify: {
      watch: {
        options: {
          title: 'Tasks Complete',
          message: 'Files Processed & Compiled',
        }
      }
    }
  });

  // Load tasks
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-newer');
  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-notify');

  // Default task(s).
  grunt.registerTask('default', []);

  grunt.task.run('notify_hooks');

};

要使子目录正常工作,您需要 globbing pattern;

'public/resources/site/scss/**/*.scss'

由于 newer,我认为您的 watch 任务存在缺陷。 Watch 检测到对 _globals 的更改,但 sass 任务只知道编译主 styles.scss。但是,newer 看到这个文件没有改变,所以它没有 运行 这一步。

尝试从监视任务列表中删除 newer