简体   繁体   English

Gulp浏览器同步不注入样式

[英]Gulp browser-sync not injecting styles

I'm trying to get browser-sync to inject styles using gulp. 我正在尝试使浏览器同步以使用gulp注入样式。 I've pretty much copied and pasted from the tutorial, but nothing happens. 我已经从本教程中复制并粘贴了很多东西,但是没有任何反应。 The sass gets compiled correctly, but the injection doesn't happen. Sass正确编译,但不会发生注入。 Any ideas what I've done wrong, or how to debug this? 任何想法,我做错了什么,或者如何调试呢?

I'm also using MAMP if it makes any difference at all. 如果它有任何区别,我也正在使用MAMP。

My Gulp file: 我的Gulp文件:

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



// Proxy Server
gulp.task('serve', ['sass'], function() {

    browserSync.init({
        proxy: "local.website.com"
    });

    gulp.watch('../css/source/*.scss', ['sass']);
});


// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
    return gulp.src('../css/source/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('../css/build'))
    .pipe(browserSync.stream());
});

gulp.task('default', ['serve']);

The response in my console: 我的控制台中的响应:

[gulp] Starting 'default'...
[gulp] Finished 'default' after 4.61 μs
[BS] Proxying: http://local.website.com
[BS] Access URLs:
 -------------------------------------
       Local: http://localhost:3000
    External: http://192.168.8.12:3000
 -------------------------------------
          UI: http://localhost:3001
 UI External: http://192.168.8.12:3001
 -------------------------------------
[gulp] Starting 'sass'...
[BS] 1 file changed (main.css)
[gulp] Finished 'sass' after 114 ms
[gulp] Starting 'sass'...
[BS] 1 file changed (main.css)
[gulp] Finished 'sass' after 115 ms

If it matters, here is my package.json: 如果有关系,这是我的package.json:

{
  "devDependencies": {
    "browser-sync": "^2.9.11",
    "gulp": "^3.9.0",
    "gulp-sass": "^2.0.4"
  }
}

The problem in my case was Drupal - it uses @import instead of link to add CSS files. 我的问题是Drupal-它使用@import而不是链接来添加CSS文件。 This module solves it! 这个模块解决了! https://www.drupal.org/project/link_css https://www.drupal.org/project/link_css

您说您已经复制了本教程中的内容,但没有复制此部分,该部分实际上将更改通知了browserSync:

gulp.watch('../css/source/*.scss').on('change', browserSync.reload);

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

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