Grunt:在文件更改后将sass转换为css(观察)



这是我的gruntfile.js:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    folders: {
       'dist': 'dist',
       'app': 'app'
    },
// configure jshint to validate js files -----------------------------------
jshint: {
  options: {
    reporter: require('jshint-stylish'),
    ignores: [
    'Grunfile.js',
    'app/assets/lib/**/*'
    ]
  },
  all: [
  'app/**/**/*.js',
  ]
},
// configure uglify to minify js files -------------------------------------
uglify: {
  options: {
    banner: '/*n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> n*/n'
  },
  build: {
    files: {
      'dist/js/app.min.js': 'app/js/main.js'
    }
  }
},
// compile sass stylesheets to css -----------------------------------------
sass: {
  dist: {
    options: {
      style: 'expanded'
    },
    files: {
      'app/assets/css/main.css': 'app/assets/sass/main.sass',
      'app/assets/css/variables.css': 'app/assets/sass/variables.sass',
      'app/assets/css/typography.css': 'app/assets/sass/typography.sass',
      'app/assets/css/reset.css': 'app/assets/sass/reset.sass'
    }
  }
},
// starting an express server ----------------------------------------------
express: {
  dev: {
    options: {
      port: 9000,
      hostname: '0.0.0.0',
      bases: ['app'],
      livereload: true
    }
  }
},
// configure watch to auto update ------------------------------------------
watch: {
  sass: {
    files: ['**/*.{scss,sass}'],
    tasks: ['sass'],
    options: {
      livereload: true
    }
  },
  reload: {
    options: {
      livereload: true
    },
    files: ['app/**/*'],
  },
}
  });
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-express');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.registerTask('default', ['jshint', 'uglify', 'sass', 'express', 'watch:reload']);
};

我的问题:当我启动grunt时,它会检查我的sass文件并自动将其转换为css文件。检查。但是,如果我启动grunt,然后编辑一个sass文件,它会识别更改,但不会再次将sass转换为css。有人看出这个错误了吗?

干杯!

发现"问题":必须注册任务'watch'而不是'watch:reload'!

欢呼

相关内容

  • 没有找到相关文章