Grunt手表和sass没有编译.它只是注意到变化

grunt watch and sass is not compiling. It just notices change

本文关键字:注意到 变化 编译 手表 sass Grunt      更新时间:2023-09-26

我不明白为什么我的'grunt watch'命令不能编译。它只是发现已经做了一个更改,但实际上它不会将其编译到我的sass中。

这是我的gruntfiles.js

module.exports = function(grunt) {
  var devPath = 'dev/';
  var distPath = 'dist/';
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    sass: {
      dev: {
        options: {
          style: 'nested'
        },
        files: [{
          expand: true,
          cwd: devPath + 'scss/',
          src: ['*.scss'],
          dest: devPath + 'css/',
          ext: '.css'
        }]
      }
    },
    watch: {
      css: {
        files: [devPath + '**/*.scss'],
        tasks: ['sass:dev']
      }
    },
    emailBuilder: {
      test: {
        files: [{
          expand: true,
          cwd: 'dev/',
          src: ['*.html'],
          dest: 'dist/',
          ext: '.html',
        }]
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-email-builder');
  grunt.registerTask('sass', ['sass']);
  grunt.registerTask('dist', ['emailBuilder']);
  grunt.registerTask('default', ['watch']);
};

然后是我在终端中看到的:

正在运行"watch"任务等待…

文件"/dev/scss风格。scss"改变。

你在你的sass任务中有一个无限循环,只要删除下面的行:

grunt.registerTask('sass', ['sass']);

我认为您需要更改您的sass conf

    files: [{
      expand: true,
      cwd: devPath,
      src: ['scss/**/*.scss'],
      dest: devPath + 'css/',
      ext: '.css'
    }]