使用 Grunt watch 和 SASS 时出错

Error using Grunt watch and SASS

我正在尝试在 Windows 上将 grunt watch t 与 SASS 一起使用,但每次我都会收到错误消息

Waiting...
OK
>> File "scss\main.scss" changed.

Running "sass:dist" (sass) task
Error: Error generating source map: couldn't determine public URL for the source stylesheet.
No filename is available so there's nothing for the source map to link to.

on line  of standard input
Use --trace for backtrace.

Warning: Error: Error generating source map: couldn't determine public URL for the source stylesheet.
No filename is available so there's nothing for the source map to link to.

on line  of standard input
Use --trace for backtrace. Use --force to continue.

Aborted due to warnings.
Completed in 0.769s at Wed May 13 2015 10:55:24 GMT+0200 (W. Europe Daylight Time)

我在这里找到了一个 similar question,但它对我不起作用

我的package.json:

{
  "name": "Test",
  "version": "1.0.0",
  "description": "Test thingy",
  "author": "Me",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-sass": "~0.3.0",
    "grunt-contrib-watch": "~0.4.4"
  }
}

我的Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        sass: {
            dist: {
                options: {
                    style: 'compressed'
                },
                files: {
                    'css/style.css' : 'sass/style.scss'
                }
            }
        },
        watch: {
            css: {
                files: '**/*.scss',
                tasks: ['sass'],
                options: {
                    spawn: false
                }
            }
        },
    });

    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default',['watch']);
}

软件版本:

grunt-cli v0.1.13

grunt v0.4.5

Sass 3.4.13 (Selective Steve)

ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32]

Compass 1.0.3 (Polaris)

npm 2.7.4

node v0.12.2

我已经尝试更新所有软件包,甚至重新安装所有组件,但这没有帮助。谁能帮帮我?

尝试禁用 sourcemap 看看是否有效。

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        sass: {
            dist: {
                options: {
                    style: 'compressed',
                    sourcemap: 'none'
                },
                files: {
                    'css/style.css' : 'sass/style.scss'
                }
            }
        },
        watch: {
            css: {
                files: '**/*.scss',
                tasks: ['sass'],
                options: {
                    spawn: false
                }
            }
        },
    });

    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default',['watch']);
}

您的 grunt-contrib-sass 版本已过时尝试将 package.json 更改为:

{
  "name": "Test",
  "version": "1.0.0",
  "description": "Test thingy",
  "author": "Me",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-sass": "~0.9.0",
    "grunt-contrib-watch": "~0.4.4"
  }
}