[已解决]grunt sass自动编译的问题

背景

  • 第1次使用sass
  • 第1次配置gruntfile.js

问题

通过grunt自动编译sass文件为css文件,总是报错
为什么要报错呢?

$ grunt
Running "sass:dist" (sass) task
Error: Invalid CSS after ".test ": expected selector, was "{color:red;}"
        on line 1 of test.sass
  Use --trace for backtrace.
Warning: Exited with error code 13 Use --force to continue.

Aborted due to warnings.

代码

Gruntfile.js

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.initConfig({
        sass: { 
            dist: { 
                files: {
                    'test.css':'test.sass'
                }
            }
        }
    });
    grunt.registerTask('default',['sass']);
}

test.sass

.test {
    color:red;
}

解决

test.sass修改成test.scss就行了

原因

sassscss的语法不一样
花括号{}和分号 ;scss里面的语法

参考

http://sass.bootcss.com/docs/...

阅读 3.1k
1 个回答

解决
把test.sass修改成test.scss就行了

原因
sass和scss的语法不一样
花括号{}和分号 ;是scss里面的语法

参考
http://sass.bootcss.com/docs/...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进