咕噜咕噜看着没有编译所有sass文件尽管被观看"

时间:2015-11-11 09:20:49

标签: javascript gruntjs grunt-contrib-watch

基本上,目前我有2个问题似乎无法找到答案。 当我保存我的主styles.scss时,sass编译好了,但是当我保存_globals.scss或任何其他scss文件时,grunt watch似乎检测到了变化,但它没有编译!我需要做些什么来纠正这个问题?

我的第二个问题是我在scss文件夹中的目录中有一个scss文件,例如:pages/_gallery.scss(正在主styles.scss中导入),grunt watch doesn'看到它,我明白这可能是因为我的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');

};

1 个答案:

答案 0 :(得分:1)

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

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

我认为由于newer,您的观看任务存在缺陷。 Watch检测到对_globals的更改,但sass任务只知道编译主styles.scss。但是,newer发现此文件未更改,因此它不会运行该步骤。

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