使用Grunt手表和SASS时出错

时间:2015-05-13 09:36:10

标签: node.js sass gruntjs

我正在尝试在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(选择性史蒂夫)

     

ruby​​ 2.2.2p95(2015-04-13修订版50295)[x64-mingw32]

     

指南针1.0.3(北极星)

     

npm 2.7.4

     

节点v0.12.2

我尝试更新所有软件包,甚至重新安装了所有组件,但这并没有帮助。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

尝试禁用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"
  }
}