9

我已经得到了我Gulpfile的编译sass,并且只是“live-reload远离倾销codekit”。我正在努力让这种风格注入工作。我正在尝试进行设置:https ://github.com/vohof/gulp-livereload

当我在终端中运行 gulp 时,它似乎编译了 sass,但它没有注入样式。我究竟做错了什么?我在 chrome + 以下节点模块中安装了 livereload 扩展:

  "devDependencies": {
    "gulp": "~3.5.0",
    "gulp-sass": "~0.6.0"
  },
  "dependencies": {
    "gulp-livereload": "~0.2.0",
    "tiny-lr": "0.0.5"
  }

我的 gulpfile 看起来像这样:

var gulp = require('gulp');

//plugins
var sass = require('gulp-sass'),
    lr = require('tiny-lr'),
    livereload = require('gulp-livereload'),
    server = lr();

gulp.task('sass', function () {
    gulp.src('./scss/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./'))
        .pipe(livereload(server));
});


// Rerun tasks when a file changes
gulp.task('watch', function () {
    server.listen(35729, function (err) {

        if (err) return console.log(err);

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

    });
});





// The default task (called when you run 'gulp' from cli)
// "sass" compiles the sass to css
// "watch" looks for filechanges, and runs tasks accordingly
gulp.task('default', ['sass', 'watch']);

任何帮助深表感谢。谢谢!

4

6 回答 6

12

你在跑本地主机吗?从 Chrome 中的插件进入设置并检查文件 url 的选项:chrome://extensions/

于 2014-01-28T15:55:26.713 回答
4

如果您正在使用gulp-livereload,我认为使用也没有意义tiny-lr

您可以在此处找到 LiveReload 集成的工作示例:

https://github.com/kriasoft/spa-seed.front-end - SPA 前端入门工具包

于 2014-04-19T14:59:48.407 回答
4

刚刚看到这个精彩的教程,解释了使用 Gulp 启动和运行 Livereload 的所有要点:

http://rhumaric.com/2014/01/livereload-magic-gulp-style/

于 2014-04-26T15:37:58.117 回答
2

This is my solution

  • In need only this npm modules npm install gulp gulp-sass gulp-livereload express --save-dev

  • Put the Scss-Files in /app/styles and Html-Files in /app/

  • Install the live-reload-plugin for Chrome.

  • Go to http://localhost:4000 and activate the pluin for the current tab

Done :-)

(Don't forget to change the sass-settings for your Project. Set indentedSyntax to false if you are using scss instead of sass)

var gulp = require('gulp'),
  sass = require('gulp-sass'),
  livereload = require('gulp-livereload');

gulp.task('sass', function() {
  gulp.src('app/styles/*.sass')
    .pipe(sass({
      includePaths: ['app/styles'],
      indentedSyntax : true,
      errLogToConsole: true
    }))
    .pipe(gulp.dest('app/css'))
    .pipe(livereload());
});

gulp.task('serve', function(done) {
  var express = require('express');
  var app = express();
  app.use(express.static(__dirname + '/app'));
  app.listen(4000, function () {
     done();
  });
});

gulp.task('html', function() {
  gulp.src('app/**/*.html')
    .pipe(livereload());
});

gulp.task('watch', function() {
  gulp.watch('app/styles/*.sass', ['sass']);
  gulp.watch('app/**/*.html', ['html']);

  livereload.listen();
});

gulp.task('default', ['watch', 'serve']);
于 2015-01-17T14:07:41.240 回答
2

我已经通过浏览器扩展启用了 livereload,但我需要做的最后一件事是单击此按钮以在单个选项卡上“激活”它。 在此处输入图像描述

于 2015-12-22T11:50:46.593 回答
1

我在不需要浏览器插件的情况下运行 gulp 和 livereload。

var http = require('http')
, path = require('path')
, Promise = Promise || require('es6-promise').Promise
, express = require('express')
, gulp = require('gulp')
, log = require('gulp-util').log
, tinylr = require('tiny-lr')
, livereload = require('gulp-livereload')

, ROOT = 'dist'
, GLOBS = [path.join(ROOT, "/**/*")]
, PORT = 8000
, PORT_LR = PORT + 1

, app = express()
;

app.use(require('connect-livereload')({port: PORT_LR}))
app.use('/', express.static("./dist"))

http.createServer(app).listen(PORT, function() {
  log("Started express server on http://localhost:" + PORT);
});

lrUp = new Promise(function(resolve, reject) {
  lrServer = tinylr()
  lrServer.listen(PORT_LR, function(err) {
    if (err) return reject(err)
    resolve(lrServer)
  })
})

gulp.watch(GLOBS, function(evt) {
  if (evt.type === 'deleted') return

  lrUp.then(function(lrServer) {
    log("LR: reloading", path.relative(ROOT, evt.path));
    gulp.src(evt.path).pipe(livereload(lrServer))
  })
  .catch(console.log)
});

请享用 :)

于 2014-05-19T03:03:32.023 回答