简体   繁体   English

NPM无法转换SASS

[英]NPM failed to convert SASS

I am trying to convert my style.scss (which has some other files link to it such as _variable.scss , _mixins.scss ) file to css via grunt.js and npm . 我试图通过grunt.jsnpm将我的style.scss (其他一些文件链接到它,例如_variable.scss_mixins.scss )文件转换为css。 however I got this error: 但是我收到了这个错误:

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

Here's my gruntfile.js : 这是我的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']);
};

When I run grunt sass , it gave me those error. 当我运行grunt sass ,它给了我那些错误。 Compass was already installed and I type "grunt compass" to make sure its running. 指南针已经安装,我输入“grunt compass”以确保其运行。

Any idea? 任何的想法?

use grunt-contrib-sass instead of grunt-sass . 使用grunt-contrib-sass代替grunt-sass

This task requires you to have Ruby and Sass installed. 此任务要求您安装Ruby和Sass。 If you're on OS X or Linux you probably already have Ruby installed; 如果你在OS X或Linux上,你可能已经安装了Ruby; test with ruby -v in your terminal. 在你的终端用ruby -v测试。 When you've confirmed you have Ruby installed, run gem install sass to install Sass. 当您确认已安装Ruby时,请运行gem install sass以安装Sass。

Also make sure to compass option to true . 还要确保compass选项为true By default, it's set to false . 默认情况下,它设置为false

Read this for more information : compass option 阅读本文以获取更多信息: 罗盘选项

Here is an example : 这是一个例子:

sass: {
        dist: {
            options: {                 
                compass: true,
            },
            files: {
                'css/style.css' : 'sass/style.scss'
            }
        }
    },
  • grunt-sass uses libsass which is a Sass compiler in C++ that doesn't support compass. grunt-sass使用libsass,它是C ++ 中不支持罗盘的Sass编译器

This task uses libsass which is a Sass compiler in C++. 此任务使用libsass,它是C ++中的Sass编译器。 In contrast to the original Ruby compiler, this one is much faster, but is missing some features, though improving quickly. 与原始的Ruby编译器相比,这个更快,但是缺少一些功能,尽管快速改进。 It also doesn't support Compass. 它也不支持指南针。 Check out grunt-contrib-sass if you prefer something more stable, but slower. 如果你喜欢更稳定但更慢的东西,请查看grunt-contrib-sass。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM