-->

Gulp-sass will not compile to CSS

2019-03-02 15:27发布

问题:

I'm not able to get grunt-sass to compile to .css. Have seen a load of other similar posts and utilized suggestions but nothing seems to work.

I can get other plugins working fine (for example 'del' to delete stuff, shown here) so it seems my environment is ok, and i can get ordinary vanilla sass compile/watch to work fine.

Here's my setup just in case:

OSX Maverics 10.9.5

$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin13]

$ sass -v
Sass 3.4.9 (Selective Steve)

$ npm -v
2.1.12

$ brew -v
Homebrew 0.9.5

Here's the project directory structure:

    ├── index.html
    │   
    ├── scss
    │    └── base.scss
    │          ├── _partial1.scss
    │          └── _partial2.scss
    │
    ├── assets
    │      └── css
    │           └── Nothing yet!
    │
    ├── deltest
    │    └── save.txt
    │
    ├── gulpfile.js
    │
    └── node_modules
         └── etc ...

Here's my gulpfile.js:

var gulp = require('gulp');
var sass = require('gulp-sass');
var del = require('del');

gulp.task('gsas', function() {
    gulp.src('./scss/base.scss')
        .pipe(sass({ includePaths : ['./scss/'] }))
        .pipe(gulp.dest('./assets/css'))
});

del(['!deltest/save.txt', 'deltest/delete.txt'], function (err, deletedFiles) {
    console.log('Files deleted:', deletedFiles.join(', '));
});

gulp.task('default', function() {
    console.log('AAAAAAAAAAAAAAAARGH!');
});

Can anyone see what is wrong here?


UPDATED - with same task silently failing on a windows box:

Here's the gulpfile.js from the windows box test and I'm not even @importing any partials (the dir structure is exactly as shown in the task setup, which i pulled straight from the actual plugin example):

var gulp = require('gulp');
var sass = require('gulp-sass');
var del = require('del');

gulp.task('sass', function () {
    gulp.src('./scss/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./css'));
});

del(['delete/delete.txt', '!delete/save.txt'], function (err, deletedFiles) {
    console.log('Files deleted:', deletedFiles.join(', '));
});

gulp.task('default', function () {
    console.log("Made it!");
});

In this example again I'm getting the 'del' task to run fine but gulp-sass fails silently and it's really baffling.

回答1:

If you want the sass task to execute when you run gulp from the command-line, add it as a dependency of the default task:

gulp.task('default', ['sass'], function() {
  //other stuff
});