【问题标题】:Syntax Error in Gruntfile.js - Sass WatchGruntfile.js 中的语法错误 - Sass Watch
【发布时间】:2014-05-26 04:55:12
【问题描述】:

我是第一次使用 grunt.js,但在设置 sass 手表时遇到了问题。我已经成功安装了 node.js 和 grunt,并且能够将我的所有 javascript 文件连接并缩小到一个文件中。然后我开始尝试让它监视和编译我的 sass 文件,但我不知道为什么我在命令行中不断收到此错误(显然存在语法错误,但我不知道它在哪里?

这是我的命令行错误: Mandy 在 MandysMac 在 ~/Desktop/Dropbox/WEBSITES/Portfolio/wp-content/themes/mandy_made_this_theme on master* $咕噜声

 /Users/Mandy/Desktop/Dropbox/WEBSITES/Portfolio/wp-content/themes/mandy_made_this_theme/Gruntfile.js:27
  watch: {
  ^^^^^
 Loading "Gruntfile.js" tasks...ERROR
 >> SyntaxError: Unexpected identifier
 Warning: Task "default" not found. Use --force to continue.

 Aborted due to warnings.

这是我的 package.json 文件:

 {
   "name": "mandy-made-this-theme",
   "version": "0.1.0",
   "devDependencies": {
   "grunt": "~0.4.2",
   "grunt-contrib-jshint": "~0.6.3",
   "grunt-contrib-nodeunit": "~0.2.0",
   "grunt-contrib-uglify": "~0.2.2",
   "grunt-contrib-sass": "^0.7.3",
   "grunt-contrib-watch": "^0.6.1"
   }
}

最重要的是,这是我的 grunt 文件:

module.exports = function(grunt) {

 // Project configuration.
  grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  uglify: {
  options: {
    banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
  },
  build: {
    src: ['working/jquery-2.1.0.min.js, working/jquery-ui-1.10.4.custom.min.js',  'working/jquery.smooth-scroll.min.js', 'working/isotope.pkgd.min.js', 'working/scripts.js'], //input
    dest: 'scripts/build/scripts.min.js' //output
   }
  },

  sass: {                            
    dist: {                           
      options: {                      
        style: 'expanded'
      },
      files: {                     
        'style.css': 'sass/style.scss'       
      }
    }
  }

  watch: {
      css: {
        files: '**/*.scss',
        tasks: ['sass'],
        options: {
          livereload: true,
        }
      }
    }

  });

 // Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');

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

}

【问题讨论】:

    标签: sass gruntjs watch


    【解决方案1】:

    sass 对象后缺少逗号

            'style.css': 'sass/style.scss'       
          }
        }
      }, // added , here
    
      watch: {
          css: {
            files: '**/*.scss',
    

    【讨论】:

    • 所以如果你已经在使用 grunt,添加类似 jshint 的任务来检查你的代码,如果你的 IDE 不支持它
    • 虽然如果你的 Gruntfile 中有语法错误,jshint grunt 任务将无法帮助你修复它:-)
    • 是的,不幸的是,我的 sass watch 后缺少的逗号不是问题。
    • @steveax 是的,经典的鸡蛋问题,我没有想到 :-) 但是对其他文件有帮助,然后是 Gruntfile 本身
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 2015-02-13
    • 2018-12-14
    • 1970-01-01
    相关资源
    最近更新 更多