【问题标题】:JavaScript SyntaxError: Unexpected identifier when setting Grunt tasksJavaScript SyntaxError:设置 Grunt 任务时出现意外标识符
【发布时间】:2018-02-21 22:21:32
【问题描述】:

我正在尝试为 Grunt 设置几个任务,但似乎有一个我找不到的错误。 JSlint 指出 watch 部分有以下错误:

意外的令牌,预期的,

在终端中我得到:

SyntaxError:意外标识符警告:找不到任务“默认”。使用 --force 继续。

module.exports = function(grunt) {
  grunt.initConfig({

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

    sass: {
      dev: {
        options: {
          style: 'expanded',
          sourcemap: 'none'
        },
        files: {
          'compiled/style.css':'sass/style.scss'
        }
      },
      dist: {
        options: {
          style: 'compressed',
          sourcemap: 'none'
        },
        files: {
          'compiled/style-min.css': 'sass/style.scss'
        }
      }
    }

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

  });

  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.registerTask('default',['watch']);
}

【问题讨论】:

  • 我认为sass: {...}watch: {...}任务之间应该有一个逗号“,”

标签: javascript sass gruntjs


【解决方案1】:

我相信您在 Watch 之前缺少一个逗号。

module.exports = function(grunt) {
  grunt.initConfig({

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

    sass: {
      dev: {
        options: {
          style: 'expanded',
          sourcemap: 'none'
        },
        files: {
          'compiled/style.css':'sass/style.scss'
        }
      },
      dist: {
        options: {
          style: 'compressed',
          sourcemap: 'none'
        },
        files: {
          'compiled/style-min.css': 'sass/style.scss'
        }
      }
    },

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

  });

  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.registerTask('default',['watch']);
}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 2020-05-15
    • 2019-10-28
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多