使用gulp + foundation(sass版本)时出错

时间:2017-02-28 12:00:21

标签: css ruby gulp gulp-sass gulp-ruby-sass

我想使用gulp + Foundation 6 + browserify。 当在cli中运行gulp时,我在终端中有这个错误

write ./scss.css/foundation.css
path.js:7
throw new TypeError('Path must be a string. Received ' + inspect(path));
^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.join (path.js:1211:7)
    at exports.replaceLocation (/Applications/MAMP/htdocs/Jober/node_modules/gulp-ruby-sass/lib/utils.js:32:14)
    at /Applications/MAMP/htdocs/Jober/node_modules/gulp-ruby-sass/index.js:179:13
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:416:3)

我的gulpfile.js是:

var gulp        = require ('gulp'),
    logger      = require ('gulp-util'),
    concat      = require ('gulp-concat'),
    minifyCSS   = require ('gulp-minify-css'),
    compileSass = require ('gulp-ruby-sass');

var scss_sources,
    input_address,
    output_address;

// Input and Output Address
    input_address  = 'asstes/src/';
    output_address = 'asstes/dist/';

// Style Sources
    scss_sources = [
        'node_modules/foundation-sites/scss',
        input_address + 'style/style.scss'];

    gulp.task('styles', function(){
        return compileSass(scss_sources, { style: 'expanded' })
               .pipe(autoprefixer({
                   browsers: ['last 2 versions', 'ie >= 9', 'and_chr >= 2.3'],
                   cascade: false
               }))
               .pipe(minifyCSS())
               .on('error', logger.log)
               .pipe(gulp.dest(output_address + 'style'));
    });

gulp.task('watch', function(){
    gulp.watch(input_address + 'style/pages/*.scss', ['styles']),
});

gulp.task('default', ['styles' , 'watch']);

我的style.scss是:

//Modules
@import 'foundation';

//Pages
@import 'pages/index';

我的文件夹结构是:

PROJECT FOLDER
    |
    |_assets
    |    |_dist
    |    |   |_img
    |    |   |_js
    |    |   |_style
    |    |
    |    |_src
    |        |_img
    |        |_js
    |        |_style
    |
    |_node_modules
    |        |_foundation-site
    |
    |_gulpfile.js

我在gulp-ruby-sass之前使用gulp-compass,但是有一个流行的错误:Individual stylesheets must be in the sass directory,因此将插件更改为gulp-ruby-sass。

我该如何解决?

1 个答案:

答案 0 :(得分:0)

字符串连接可能无法在scss_sources中正常工作。

尝试将scss_sources更改为:

scss_sources = [
     'node_modules/foundation-sites/scss',
     'asstes/src/style/style.scss'
];

看看是否有效,如果是这样,它就是连接。