【问题标题】:Gruntfile.js watchGruntfile.js 观看
【发布时间】:2013-10-19 19:06:47
【问题描述】:

所以我正在制作自己的 Wordpress 框架,并使用 grunt 和 sass。我在 grunt 和 sass 方面较新,但对 grunt 的经验足够了解我在做什么,但我过去使用 LESS 而不是 Sass。

我以来自roots.io 的Gruntfile.js 文件作为起点。据我所知,我所拥有的一切都是正确的,但我对一些事情不太确定。我删除了 js 的东西,因为我不会关注它,我添加了 grunt-contrib-sass。

运行 grunt watch 时出现此错误:

 grunt watch

/Gruntfile.js:22
        watch: {
        ^^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "watch" not found. Use --force to continue.

Aborted due to warnings.

下面是我的 Gruntfile.js 和我的 package.json

Gruntfile.JS

'use strict';
module.exports = function (grunt) {

    grunt.initConfig({
        version: {
            options: {
                file: 'lib/scripts.php',
                css: 'assets/css/main.min.css',
                cssHandle: 'su_styles'
            }
        },
        sass: {
            dist: {
                options: {
                    style: 'compressed'
                },
                files: {
                    'assets/css/main.min.css': [
                    'assets/scss/app.scss'
                    ]
                }
            }
        },
        watch: {
            sass: {
                files: [
          'assets/scss/*.scss',
          'assets/scss/foundation/*.scss'
                ],
                tasks: ['sass', 'version']
            },
            livereload: {
                // Browser live reloading
                // https://github.com/gruntjs/grunt-contrib-watch#live-reloading
                options: {
                    livereload: false
                },
                files: [
          'assets/css/main.min.css',
          'templates/*.php',
          '*.php'
                ]
            }
        },
        clean: {
            dist: [
        'assets/css/main.min.css'
            ]
        }
    });

    // Load tasks
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-wp-version');
    grunt.loadNpmTasks('grunt-contrib-sass');

    // Register tasks
    grunt.registerTask('default', [
    'clean',
    'version',
    'sass'
    ]);
    grunt.registerTask('dev', [
    'watch'
    ]);

};

package.json - 取出一些东西以保护一点隐私

{
  "name": "sudoh",
  "version": "1.0.0",
  "author": "Brandon Shutter <brandon@brandonshutter.com>",
  "licenses": [
    {
      "type": "MIT",
      "url": "http://opensource.org/licenses/MIT"
    }
  ],
  "engines": {
    "node": ">= 0.10.0"
  },
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-wp-version": "~0.1.0",
    "grunt-contrib-sass": "~0.5.0"
  }
}

提前感谢您的帮助。

【问题讨论】:

  • 所以,是的,只是删除那个答案,因为它没有帮助。也就是说,如果npm install 运行良好,我唯一一次看到此错误是 Gruntfile(或任务 JS 本身)中存在 JS 语法问题。
  • 使用--verbose 运行时添加的任何有用信息?
  • 我拿走了你的 gruntfile 并手动安装了所有插件,除了 wordpress 插件。这对我来说很好。我认为您有安装问题,或者您的 gruntfile 本身有问题。错误描述对我来说像是语法错误。

标签: wordpress sass gruntjs grunt-contrib-watch


【解决方案1】:

看来我的设置没有任何问题。我的代码编辑器(括号)出于某种原因添加了隐藏字符并导致语法错误。切换到 Sublime 并再次保存文件使其完美运行。

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    相关资源
    最近更新 更多