【问题标题】:Local preprocessing with Gulp, Stylus, and Browser-sync使用 Gulp、Stylus 和浏览器同步进行本地预处理
【发布时间】:2026-02-09 18:20:14
【问题描述】:

我正在尝试为 Windows 上的客户端设置 CSS 预处理和浏览器同步。 Prepros 似乎很垃圾,而且他不能使用 codeKit,因为它只有 Mac。

我给了他这些资源:https://webdesign.tutsplus.com/tutorials/supercharge-your-local-wordpress-development--cms-28303https://browsersync.io/docs/gulp

预处理效果很好,但必须手动刷新浏览器才能看到 CSS 更改。

您能发现这段代码中有什么不正确的地方吗? MAMP 也参与其中......所以它可能是别的东西。我正在尝试不同的配置来解决问题。

// gulpfile.js
var gulp = require('gulp');
var browserSync = require('browser-sync');
var stylus = require('gulp-stylus');

gulp.task('setup-server', function() {
  var files = [
    './style.css',
    './*.php',
  ];
  browserSync.init(files, {
    proxy: 'https://website-name.dev',
  });
});

gulp.task('compile-stylus', function () {
  return gulp.src('stylus/*.styl')
    .pipe( stylus({
      // options
    }))
    .pipe( gulp.dest('./') ) // root of theme
    .pipe( browserSync.stream() )
  ;
});

gulp.task('default', ['setup-server', 'compile-stylus'], function() {
  gulp.watch('stylus/**/*.styl', ['compile-stylus']);
});


文件结构

项目根 gulpfile.js /手写笔 /部分 样式.styl

【问题讨论】:

    标签: gulp mamp browser-sync gulp-stylus


    【解决方案1】:

    试试这些改变:

    var browserSync = require("browser-sync").create();
    var reload = browserSync.reload;
    

    以及在任务结束时进行以下更改:

    gulp.task('compile-stylus', function () {
      return gulp.src('stylus/*.styl')
        .pipe( stylus({
          // options
        }))
        .pipe( gulp.dest('./') ) // root of theme
        .pipe( browserSync.reload({stream: true}));
    });
    

    我假设您的文件夹结构中的意思是 gulpfile.js 而不是 gruntfile.js。

    【讨论】:

    • 我的意思是 gulpfile.js ; ) 我会试试看!
    最近更新 更多