NPM未能转换SASS

我想通过grunt.jsnpm将我的style.scss (其中有一些其他文件链接到它,如_variable.scss_mixins.scss )文件转换为CSS。 但是我得到这个错误:

 Error: File to import not found or unreadable: compass. on line 5 of sass/style.scss 1: // typorgraphy 2: @import "base/typography"; 3: 4: // compass 5: @import "compass"; 6: 7: // import files 8: @import "base/import"; 9: 10: // mixins 

这是我的gruntfile.js

 module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), compass: { dist: { options: { sassDir: 'sass', cssDir: 'css', environment: 'production' } }, dev: { options: { sassDir: 'sass', cssDir: 'css' } } }, watch: { sass:{ files: ['sass/*.scss'], tasks: ['sass', 'cssmin'] } }, sass: { dist: { files: { 'css/style.css' : 'sass/style.scss' } } }, concat: { options: { separator: ';', stripBanners: true, banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, dist: { src: ['js/*.js'], dest: 'js/main.min.js' } }, uglify:{ options: { manage: false, preserveComments: 'all' //preserve all comments on JS files }, my_target:{ files: { 'js/main.min.js' : ['js/*.js'] } } }, cssmin:{ my_target:{ files: [{ expand: true, cwd: 'css/', src: ['*.css', '!*.min.css'], dest: 'css/', ext: '.min.css' }] } } }); // Load the plugin that provides the "compass" task. grunt.loadNpmTasks('grunt-contrib-compass'); // Load the plugin that provides the "watch" task. grunt.loadNpmTasks('grunt-contrib-watch'); // Load the plugin that provides the "sass" task. grunt.loadNpmTasks('grunt-contrib-sass'); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Load the plugin that provides the "concat" task. grunt.loadNpmTasks('grunt-contrib-concat'); // Load the plugin that provides the "cssmin" task. grunt.loadNpmTasks('grunt-contrib-cssmin'); // Default task(s). grunt.registerTask('default', ['uglify','cssmin']); }; 

当我运行grunt sass ,它给了我那些错误。 指南针已经安装好了,我input“grunt compass”来确保它正在运行。

任何想法?

使用grunt-contrib-sass而不是grunt-sass

  • grunt-contrib-sass ruby编译器,支持指南针。

这个任务需要你安装Ruby和Sass。 如果你在OS X或者Linux上,你可能已经安装了Ruby; 用ruby -v在你的terminaltesting。 当你确认你已经安装了Ruby,运行gem install sass来安装Sass。

还要确保compass选项为true 默认情况下,它被设置为false

阅读这个更多的信息: 指南针选项

这里是一个例子:

 sass: { dist: { options: { compass: true, }, files: { 'css/style.css' : 'sass/style.scss' } } }, 
  • grunt-sass使用libsass,它是C ++中的一个Sass编译器, 不支持指南针。

这个任务使用了C ++中的Sass编译器libsass。 与原始的Ruby编译器相反,这个编译器速度要快得多,但缺less一些function,虽然速度有所提高。 它也不支持Compass。 看看grunt-contrib-sass如果你更喜欢更稳定的东西,但速度更慢。