简体   繁体   English

Grunt-contrib-sass不使用指南针

[英]Grunt-contrib-sass not working with compass

I'm new to Grunt, and am trying to configure grunt-contrib-sass to work alongside Compass. 我是Grunt的新手,我正在尝试配置grunt-contrib-sass与Compass一起工作。

I'm using the grunt-contrib-sass plugin, as I need to export my .scss files to two separate destinations and I couldn't get that to work with grunt-contrib-compass. 我正在使用grunt-contrib-sass插件,因为我需要将我的.scss文件导出到两个不同的目的地,我无法使用grunt-contrib-compass。

The problem that I'm having, is that on compile of .scss files I get 'ERROR: Cannot load compass' in the terminal. 我遇到的问题是,在编译.scss文件时,我得到'错误:无法在终端中加载罗盘'。

Here's a copy of my gruntfile.js; 这是我的gruntfile.js的副本;

module.exports = function(grunt){

  grunt.initConfig({

    uglify: {
      my_target: {
        files: {
          'wp-content/themes/mytheme/js/functions.js' : [ 'components/js/*.js' ] 
        }
      }
    }, // uglify

    sass:{
      dist:{
        files: {
          'wp-content/themes/mytheme/style.css' : 'components/sass/style.scss',
          'wp-content/themes/mytheme/css/ie.css' : 'components/sass/ie.scss '
        },
      options: {
        compass: true,
      }
    }
  },

  watch: {
    scripts : {
      files: ['components/js/*.js'],
      tasks: ['uglify']
    },
    css: {
      files: [ 'components/sass/*.scss'],
      tasks: [ 'sass' ],
      options: { livereload: true }
    },
    livereload: {
      options: { livereload: true },
      files: ['wp-content/themes/mytheme/'],
    },
  } // watch

})

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask( 'default', 'watch' );

} // exports

Thanks! 谢谢!

Grunt-contrib-sass doesn't support Compass versions less than v1.0.0 (which is in alpha at the time of writing). Grunt-contrib-sass不支持小于v1.0.0的Compass版本(在撰写本文时为alpha版)。

After updating Compass with; 用Compass更新Compass后;

gem install compass --pre

everything appears to work fine on compilation. 一切似乎在编译时都能正常工作。 The same gruntfile.js was used as above. 如上使用相同的gruntfile.js。

Removing all versions of sass except of known working version 3.2.19 solved the problem for me. 除了已知的工作版本3.2.19之外,删除所有版本的sass解决了我的问题。

$ sudo gem uninstall sass
Select gem to uninstall:
 1. sass-3.2.3
 2. sass-3.2.5
 3. sass-3.2.19
 4. sass-3.3.5
 5. All versions
> 4

According to the grunt-contrib-compass github page you need to have Ruby, Sass and Compass installed as prerequisite. 根据grunt-contrib-compass github页面,您需要安装Ruby,Sass和Compass作为先决条件。 You are using grunt-contrib-sass instead of grunt-contrib-compass . 你正在使用grunt-contrib-sass而不是grunt-contrib-compass See examples on the contrib-compass github. 请参阅contrib-compass github上的示例

I found another way to get compass to work without the ruby gem. 我找到了另一种让指南针在没有红宝石宝石的情况下工作的方法。 (it is a bit of work though). (虽然这有点工作)。

Go to https://github.com/Compass/compass and get the code. 转到https://github.com/Compass/compass并获取代码。 Copy the contents of core/stylesheets/compass into your sass/scss folder. 将core / stylesheets / compass的内容复制到sass / scss文件夹中。 Now you can use the normal import-rules from the compass-website. 现在您可以使用指南针网站上的常规导入规则。

BUT: 但:

You probably have to change some imports from compass like import "compass/support"; 您可能需要更改一些来自指南针的import "compass/support"; ,例如import "compass/support"; in _transitions.scss to import "../support"; 在_transitions.scss中import "../support";

grunt-contrib-sass perfectly works with compass, just add compass: true to options. grunt-contrib-sass完美适用于指南针,只需添加指南针:true即可。 I read this point on oficial git repository. 我在onicial git存储库中读到了这一点。

Example

sass: {
        dist: {
            options: {
                style: 'expanded',
                compass: true
            },
            files: [
                {
                    expand: true,
                    cwd: 'ipa-framework/src/css/scss',
                    src: ['*.scss'],
                    dest: 'ipa-framework/src/css',
                    ext: '.css'
                }
            ]
        }
    }

So none of the answers worked exactly for me but it did help me solve the issue. 所以这些答案都不适用于我,但它确实帮助我解决了这个问题。

When you install compass using gem install compass --pre 使用gem install compass --pre

it installs another version of sass, so dont install sass at all let the compass install do it for you. 它安装了另一个版本的sass,所以不要安装sass,让指南针安装为你做。

So to get it to work 所以要让它发挥作用

gem uninstall sass
gem install compass --pre

And for reference this is the npm libraries I needed to have to get this working 作为参考,这是我需要使用的npm库

npm install -g grunt grunt-contrib-sass grunt-contrib-watch grunt-livereload sass grunt-contrib-cssmin grunt-contrib-compass

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

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