简体   繁体   English

Sass不能用gulp / plumber / browsersync进行编译

[英]sass not compiling with gulp/plumber/browsersync

I'm just getting back into programming and trying to get the skeleton of an SPA afloat. 我只是重新开始编程,并试图使SPA浮出水面。 I've gotten it to the point where Gulp is watching all my tasks. 我已经了解到Gulp正在监视我的所有任务。 It is recognizing when I change HTML and BrowserSync is working fine without having to refresh. 它可以识别何时更改HTML并且BrowserSync可以正常工作而无需刷新。 The problem I'm having is more SCSS/CSS related. 我遇到的问题更多是与SCSS / CSS相关。 It was working the last time I checked, I did an npm update so now everything is updated. 上次检查时它在工作,我进行了npm更新,所以现在所有内容都已更新。 It doesn't seem to want to watch for changes with scss. 它似乎不想监视scss的更改。 I am thinking it is partly due to just how it is linked within files or maybe the gulpfile is setup incorrectly for a sass task. 我认为这部分是由于它如何在文件中链接,或者可能是为sass任务设置了错误的gulpfile。

My folder set up is: 我的文件夹设置为:

project app css/ scss/ index.html js/ gulpfile.js 项目应用程序css / scss / index.html js / gulpfile.js

Anyone seeing something I'm not seeing here? 有人看到我没在这里看到的东西吗? Again, everything loads up, bootstrap is applied, browsersync enabled, but no changes are being minified into CSS from my style.scss. 同样,一切都加载完毕,应用了引导程序,启用了browsersync,但是从我的style.scss到CSS的改动都没有最小化。

Thanks! 谢谢!

Gulp File: Gulp文件:

 /* Required */ var gulp = require('gulp'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var sass = require('gulp-sass'); var browserSync = require('browser-sync').create(); var reload = browserSync.reload; var plumber = require('gulp-plumber'); var autoprefixer = require('gulp-autoprefixer'); /* Scripts Task */ gulp.task('scripts', function(){ gulp.src(['app/js/**/*.js', '!app/js/**/*min.js']) .pipe(plumber()) .pipe(rename({suffix:'.min'})) .pipe(uglify()) .pipe(gulp.dest('app/js')) .pipe(reload({stream:true})); }); /* Sass Task */ gulp.task('sass', function(){ return gulp.src('app/scss/**/*.scss') .pipe(plumber()) .pipe(sass()) .pipe(autoprefixer('last 2 versions')) .pipe(gulp.dest('app/css')) .pipe(reload({stream:true})); }); /* HTML Task */ gulp.task('html', function(){ gulp.src('app/**/*.html') .pipe(plumber()) .pipe(reload({stream:true})); }); /* Browser-Sync Task */ gulp.task('default', ['browser-sync'], function () { }); gulp.task('browser-sync', function() { browserSync.init(null, { proxy: "http://localhost:5000", files: ["public/**/*.*"], browser: "opera", port: 7000, }); }); /* gulp.task('nodemon', function (cb) { var started = false; return nodemon({ script: 'server.js' }).on('start', function () { // to avoid nodemon being started multiple times // thanks @matthisk if (!started) { cb(); started = true; } }); }); */ /* Watch Task */ gulp.task('watch', function(){ gulp.watch('app/js/**/*.js', ['scripts']); gulp.watch('app/scss/**/*.scss', ['sass']); gulp.watch('app/**/*.html', ['html']); }) /* Default */ gulp.task('default', ['scripts', 'sass', 'html', 'browser-sync', 'watch']); 

Stylesheet Includes: 样式表包括:

 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <!-- Latest compiled and minified Bootstrap CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="css/style.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script> <!-- Modernizr --> 

1: Where is the output css of all those sass files going? 1:所有这些sass文件的输出CSS会去哪里? is that referenced in the html calling the styles? 是在html中引用的样式调用? 2: Maybe you are missing the destination folder? 2:也许您缺少目标文件夹? take this example: 举这个例子:

gulp.src('src/scss/application.scss')
    .pipe(sass({
      includePaths: [
       'node_modules/foundation-sites/scss',
       'node_modules/compass-mixins/lib'
      ],
      outputStyle: 'compressed'
    }).on('error', sass.logError))
    .pipe(gulp.dest('./public/css/'))

If you check last line I call gulp.dest to define the output of the sass file. 如果检查最后一行,我将调用gulp.dest来定义sass文件的输出。

You have this link: 你有这个链接:

<link rel="stylesheet" href="css/style.css">

but your sass task doesn't explicitly output "style.css" unless you have a style.scss file which would typically import all other scss files as partials (like "_colors.scss"). 但是您的sass任务不会显式输出“ style.css”, 除非您有一个style.scss文件,该文件通常会将所有其他scss文件作为部分导入(例如“ _colors.scss”)。 Note the underscore indicating that file is a partial . 请注意下划线指示该文件是partial文件。 In that case gulp-sass will create "style.css" which imports all those partials. 在这种情况下,gulp-sass将创建“ style.css”,以导入所有这些部分。 Otherwise it will create one css file for each of your non-partial scss files - but you only link to one of those. 否则,它将为您的每个非部分scss文件创建一个css文件-但您仅链接到其中一个。

The other alternative is to concat your css files into one file named "style.css". 另一种方法是concat你的CSS文件到一个名为“style.css文件”一个文件。

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

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