【问题标题】:Error using Grunt watch and SASS使用 Grunt watch 和 SASS 时出错
【发布时间】:2015-07-24 12:16:37
【问题描述】:

我正在尝试在 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

咕噜 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

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

【问题讨论】:

    标签: node.js sass gruntjs


    【解决方案1】:

    尝试禁用源映射,看看它是否有效。

    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"
      }
    }
    

    【讨论】:

    • 嘿SharpEdge。 Tnx 为了您的反应,我试过了,但结果是这样 - 运行“sass:dist”(sass)任务 弃用警告:不推荐使用不带值的 --sourcemap 传递。现在默认生成源地图,因此该标志无效。
    • 不知道为什么我使用 0.3.0 :S。非常感谢:)
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    相关资源
    最近更新 更多