【问题标题】:browserSync not recompiling SCSS filesbrowserSync 不重新编译 SCSS 文件
【发布时间】:2019-01-03 16:20:48
【问题描述】:

我刚开始使用 Gulp,但遇到了一个我找不到任何解决方案的问题。我已经阅读了关于它的每一个问题,但没有解决它。我也在使用 XAMPP 和虚拟主机。

这里是 gulpfile.js

var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');

var styleSrc = "./resources/scss";

gulp.task('default', ['watch','sass'], function(){});

// Watch for changes
gulp.task('watch', function(){

    // Serve files from the root of this project
    browserSync.init({
        proxy: 'starter.web'
    });

    gulp.watch(styleSrc,['sass']).on('change', browserSync.reload);
    gulp.watch('./public/*.php').on('change', browserSync.reload);

});

gulp.task('sass', function(){
    return gulp.src('./resources/scss/main.scss')
        .pipe(sass())
        .pipe(gulp.dest('./public/css'))
        .pipe(browserSync.reload({ stream: true }))
});

问题是,当我启动 gulp 时,它会将 scss 文件编译为 css 并启动 browserSync,然后,如果我更改了 php 文件中的任何内容,那很好,但是如果我更改了 scss 文件中的任何内容,这是我得到的输出:

cmd.exe /D /C call "C:\Users\User\AppData\Roaming\npm\sass.cmd" --no-cache --update main.scss:main.css
Could not find an option named "cache".

Usage: sass <input.scss> [output.css]
       sass <input.scss>:<output.css> <input/>:<output/>

=== Input and Output ===================
    --[no-]stdin               Read the stylesheet from stdin.
    --[no-]indented            Use the indented syntax for input from stdin.
-I, --load-path=<PATH>         A path to use when resolving imports.
                               May be passed multiple times.

-s, --style=<NAME>             Output style.
                               [expanded (default), compressed]

    --update                   Only compile out-of-date stylesheets.

=== Source Maps ========================
    --[no-]source-map          Whether to generate source maps.
                               (defaults to on)

    --source-map-urls          How to link from source maps to source files.
                               [relative (default), absolute]

    --[no-]embed-sources       Embed source file contents in source maps.
    --[no-]embed-source-map    Embed source map contents in CSS.

=== Other ==============================
    --watch                    Watch stylesheets and recompile when they change.
    --[no-]poll                Manually check for changes rather than using a native watcher.
                               Only valid with --watch.

    --[no-]stop-on-error       Don't compile more files once an error is encountered.
-i, --interactive              Run an interactive SassScript shell.
-c, --[no-]color               Whether to emit terminal colors.
-q, --[no-]quiet               Don't print warnings.
    --[no-]trace               Print full Dart stack traces for exceptions.
-h, --help                     Print this usage information.
    --version                  Print the version of Dart Sass.

Process finished with exit code 64

它不会重新编译它。有人知道发生了什么吗?

【问题讨论】:

    标签: sass gulp browser-sync gulp-watch


    【解决方案1】:

    我不是 gulp 专家

    我假设你正在使用 gulp 3

    你的代码应该是

        var gulp = require('gulp');
        var browserSync = require('browser-sync').create();
        var sass = require('gulp-sass');
    
        var styleSrc = "./resources/scss";
    
        gulp.task('sass', function(){
         return gulp.src('./resources/scss/main.scss')
            .pipe(sass())
            .pipe(gulp.dest('./public/css'))
            .pipe(browserSync.reload({ stream: true }))
        });
    
    
        gulp.task('browser-sync',['sass'] function() {
           browserSync.init({
               server: {
                  baseDir: "./"
                 }
              });
               gulp.watch(styleSrc, ['sass']);
               gulp.watch("./public/*.php").on('change', browserSync.reload);
           });
        gulp.task('default', ['sass',  'browser-sync']
    

    使用它作为你的 gulpfile.js

    然后运行 ​​gulp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2018-10-11
      • 1970-01-01
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多