13

我在使用Foundation 6文件时遇到了一些问题,由于某些原因,它们只是不包括所有 sass 组件。我尝试使用 Foundation 5 并且效果很好。

这是我的吞咽任务:

gulp.task('styles', ['clearCss'], function() {
    gulp.src('assets/sass/app.scss')
        .pipe(plumber(plumberErrorHandler))
        .pipe(sourcemaps.init())
        .pipe(sass({
            outputStyle: 'compressed'
        })
        .on('error', notify.onError(function(error) {
            return "Error: " + error.message;
        }))
        )
        .pipe(autoprefixer({
            browsers: ['last 2 versions', 'ie >= 9']
        }))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('./assets/dist/css')) 
        .pipe(browserSync.stream({match: '**/*.css'}))
        .pipe(notify({
            message: "Styles task complete!"
        }));
});

这是我的 app.scss:

// Import Foundation
@import "../components/foundation/scss/foundation";

它适用于我自己的 sass 文件,但完全忽略了基础部分。

4

6 回答 6

14

您应该导入文件foundation-sites.scss,而不是scss/foundation.scss。文件foundation.scss 只有一个@mixin foundation-everything,它包含在foundation-sites.scss 中:

@include foundation-everything;

但是foundation-sites.scss 在6.0.4 中有错误,这是我的日志:

Error in plugin 'sass'
Message:
    bower_components\foundation-sites\foundation-sites.scss
Error: File to import not found or unreadable: foundation
       Parent style sheet: stdin
        on line 1 of stdin
>> @import 'foundation';

修复:

将文件foundation-sites.scss中的第nr 1 行从 @import 'foundation';更改为@import 'scss/foundation';

于 2015-11-26T11:35:12.063 回答
13

基础 6 的正确方法:

如果您查看foundation.scss 文件(https://github.com/zurb/foundation-sites-6/blob/develop/scss/foundation.scss

是的,它导入了所有必需的组件,但是由于它们现在是 mixin 而不是常规的 sass,因此您必须通过简单地调用 mixin 来明确告诉您要使用它们。

应用程序.scss

@import 'foundation';
@include foundation-everything; // Very important if you want to include all of foundation css to your complied css

gulpfile.js

gulp.task('scss', function() {
    return gulp.src('app.scss')
        .pipe(plugins.sass(
           {includePaths: ['./node_modules/foundation-sites/scss']}
        ))
        .pipe(gulp.dest('css'))
        .pipe(plugins.notify({ message: 'Sass task complete' }));
});
于 2016-03-30T18:04:35.830 回答
2

我有 gulp-sass 与基础站点(Foundation 6)合作:

我的 main.scss 文件:

@charset 'UTF-8';
/**
 * Main SCSS
 * Version 1.0.0
 * built with foundation-sites
 */

// import custom settings
@import 'settings';

// import foundation sass
@import "../bower_components/foundation-sites/scss/foundation";

/* either include all foundation components…  //*/
@include foundation-everything;

/* or include specific foundation components //*/
// @include foundation-global-styles;
  /* include either foundation-grid… //*/
// @include foundation-grid;
  /* or foundation-flex-grid (but don't include both) //*/
// @include foundation-flex-grid;
// @include foundation-typography;
// @include foundation-button;
// @include foundation-forms;
// @include foundation-visibility-classes;
// @include foundation-float-classes;
// @include foundation-accordion;
// @include foundation-accordion-menu;
// @include foundation-badge;
// @include foundation-breadcrumbs;
// @include foundation-button-group;
// @include foundation-callout;
// @include foundation-close-button;
// @include foundation-drilldown-menu;
// @include foundation-dropdown;
// @include foundation-dropdown-menu;
// @include foundation-flex-video;
// @include foundation-label;
// @include foundation-media-object;
// @include foundation-menu;
// @include foundation-off-canvas;
// @include foundation-orbit;
// @include foundation-pagination;
// @include foundation-progress-bar;
// @include foundation-slider;
// @include foundation-sticky;
// @include foundation-reveal;
// @include foundation-switch;
// @include foundation-table;
// @include foundation-tabs;
// @include foundation-thumbnail;
// @include foundation-title-bar;
// @include foundation-tooltip;
// @include foundation-top-bar;

如果您不想加载所有基础组件,则不必加载。而不是@include foundation-everything,只是@include您需要的特定组件。

于 2016-02-18T18:39:30.250 回答
1

我对 gulp + bower 设置所做的事情: /src/scss/app.scss @import 'settings'; @import '../../bower_components/foundation-sites/scss/foundation'; @include foundation-everything; settings.scss包含我的基础变量覆盖、自定义 CSS 等。对我来说,诀窍是@import完整的文件路径,然后@include是 mixin。

虽然包含所有内容是多余的,但我更喜欢轻松开发,然后使用uncss清理死的 CSS 代码。

于 2016-01-24T04:54:33.080 回答
0

我不得不编辑基础站点的 bower.json 文件来更改 main.scss 基础 @import。

从:

"main": [
    "scss/foundation.scss",
    "js/foundation.js"
],

到:

"main": [
    "foundation-sites.scss",
    "js/foundation.js"
  ],

以及基础站点.scss 文件。

@import 'foundation';

到:

@import 'scss/foundation.scss';

我不认为这是最好的方法,但我的 sass、grunt 和 bower 知识是有限的。

于 2015-11-29T21:57:39.993 回答
0

如果您有 gulpfile,请包含“node_modules/foundation-sites/scss”,然后在您的 app.scss 或 style.scss 中执行以下操作:

@import "settings/settings";
@import "foundation";
@include foundation-everything;

这样你就可以导入 Foundation 提供的所有东西。当然,一切都可能有点矫枉过正,但这是一个可选的选择。

吞咽任务示例:

gulp.task('css', function() {
    return gulp.src(assets + 'scss/*.scss')
        .pipe(sass({
                includePaths: 'node_modules/foundation-sites/scss',
                errLogToConsole: true
            }))
            .on('error', handleError)
        .pipe(prefixer())
        .pipe(gulp.dest(themeDir))
        .pipe(browserSync.stream());
});

当然,handleError 是需要定义的。就我而言,它被定义为:

var handleError = function(err) {
  if (err) {
    var args = Array.prototype.slice.call(arguments);
    console.log(args);
    this.emit('end');
  }
};

不要忘记包含所需的依赖项。

于 2016-09-28T20:46:38.423 回答