【问题标题】:Gulp + Browsersync: Only want to inject CSSGulp + Browsersync:只想注入 CSS
【发布时间】:2017-06-03 20:54:21
【问题描述】:

我已经尝试让实时注射工作两天了...准备放弃,因为我已经阅读了码头和更多的 git is:issues than I want to repeat.

我不使用像 less 或 sass 这样的预处理器。我只想通过 Browsersync 重新加载更改后的 CSS。如果我保存文件并且设置了标题,则页面会重新加载。我已经尝试了很多选择,我的头在旋转。 这是我尝试的最新版本。有人愿意带我走正确的道路吗?

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

gulp.task('serve', function() {
    browserSync.init({
      proxy: "https://subdomain.mysite.dev",
      open: false,
      browser: 'firefox-developer',
      injectChanges: true,
      logLevel: "debug"
    });
    gulp.watch("./style.css", ['css']);
});

gulp.task('css', function() {
  return gulp.src('./style.css')
    .pipe(autoprefixer('last 2 versions'))
    .pipe(browserSync.stream());
});

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

Kubuntu Linux 17.04

浏览器同步--版本

2.18.12

节点-v

v7.10.0

npm -v

5.0.1

【问题讨论】:

  • 我猜你应该在通过 autoprefixer 之后保存你的 css 文件。你的 html 文件应该链接到那个 css 文件。
  • @TheDancingCode 添加:.pipe(gulp.dest("./")) 在自动前缀之后,但没有任何改变。在这一点上,我只是尝试在 ./ 上编辑 style.css 文件。/感谢您的想法

标签: wordpress gulp browser-sync gulp-browser-sync


【解决方案1】:

试试

.pipe(browserSync.reload({ stream:true }));

而不是

.pipe(browserSync.stream());

然后正如@The Dancing Code 所说,在您调用 autoprefixer 之后使用 gulp.dest,并确保生成的文件是您的 html 中的文件。

【讨论】:

  • 还是不行。它看起来像是在标题上。 ?rel= 会引起问题吗? 10.0.0.19:3000/app/themes/temptheme/style.css?rel=1496632333372">
  • @The Dancing Code 在进一步查看标题后,我发现了一些奇怪的东西。在初始加载或手动重新加载时,标题标签是 并显示两次。在我手动保存 style.css 后,标题标签更改为 10.0.0.19:3000/app/themes/temptheme/style.css?rel=1496633597972"> 它也被重复,但 ?rel= 数字不同......用这个做什么?
猜你喜欢
  • 1970-01-01
  • 2015-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多