简体   繁体   English

gulp,compass,live reload&partials reloads

[英]gulp, compass, live reload & partials reloads

So, I'm using gulp in my project. 所以,我在我的项目中使用gulp。

I use gulp-compass to compile my assets. 我用gulp-compass编译我的资产。

And, one of the task I have is a watch task for dev. 而且,我的任务之一是开发人员的监视任务。 like this: 像这样:

gulp.task('live', function() {
  gulp.watch('path/to/my/scss/files', function(event) {
    console.log('Event type: ' + event.type);
    console.log('Event path: ' + event.path);
    compass(event.path);
  });
});

The compass function: 指南针功能:

function compass(source) {
  return gulp.src(source)
    .pipe(
      plugins.compass({
        config_file: 'config.rb',
        css: 'path/to/my/css/files',
        sass: 'path/to/my/scss/files'
      }).on('error', errorHandler)
    )
    .pipe(gulp.dest('../web/css'))
    .pipe(plugins.livereload());
}

Note: the errorHandler function is irrelevant on my question. 注意:errorHandler函数与我的问题无关。

The reason I watch files this way is in order to make gulp-compass not compile all files, but the one that have been changed (I use this for dev, so I will be working in one file at time), this way the refresh is fast, and I don't have to wait (typically, around 30 ~ 60 seconds in compile all scss). 我以这种方式观看文件的原因是为了让gulp-compass不能编译所有文件,而是已经更改的文件(我用这个用于dev,所以我将在一个文件中工作),这样刷新很快,我不必等待(通常,编译所有scss大约30~60秒)。 gulp-compass only perform compile, not watch. gulp-compass只执行编译,而不是观察。

This works perfect when I'm working on a not partial file (ie: home.scss). 当我处理非部分文件(即:home.scss)时,这非常有效。

But if I change something on a partial, that gets included on the main scss, things goes wrong: it will compile my partial, and that is, it doesn't refresh (I guess its try to refresh a partial, no sense). 但是如果我改变某个部分的东西,它会被包含在主scss中,那么事情就会出错:它会编译我的部分,也就是说,它不会刷新(我想它会尝试刷新部分,没有意义)。

In order to make that happen, I have to do a dummy modification on the parent scss file, and the it works. 为了实现这一点,我必须对父scss文件进行虚拟修改,并且它可以工作。

I know this is due to the way I have define my taks (only send to compass one file at the time), and also due to gulp-compass perform always "compile". 我知道这是由于我定义我的taks的方式(当时只发送到罗盘一个文件),并且由于gulp-compass执行总是“编译”。

This gulp-plugin (so far) does not have the watch command (unless I patch it, and I don't want to do that). 这个gulp-plugin(到目前为止)没有watch命令(除非我修补它,我不想这样做)。

Does someone knows how to solve this situation and when I change something in a partial, "he knows" that this partials belong to a certain parent and then refresh it ? 有人知道如何解决这种情况吗?当我改变某种情况时,“他知道”这部分属于某个父母,然后刷新它?

So far, I can do the dummy modification on the parent or watch explicitly the parent scss Im working on, but would love to have this automatic. 到目前为止,我可以对父母进行虚拟修改或明确地观察我正在进行的父scss,但是我希望能够自动进行。

I think one solution could be create a map with all parents of the partial (reading files directly) and in case a partial is modify, update all parents and refresh, but maybe thats "too expensive". 我认为一个解决方案可以创建一个地图与所有部分父母(直接读取文件),如果部分修改,更新所有父母和刷新,但也许这“太贵”。 Maybe this can be some sort of "warm-up"... 也许这可能是某种“热身”......

Does someone have the same problem ? 有人有同样的问题吗? How you work with partials and a watch / live-reload environment ? 你如何使用partials和watch / live-reload环境?

The goal of all this is to write code and have my browser updates, so I can see in real time my advances and prevent cross browser problems (few browsers open at the same time and being refreshing dynamically). 所有这一切的目标是编写代码并让我的浏览器更新,因此我可以实时查看我的进展并防止跨浏览器问题(少数浏览器同时打开并动态刷新)。

Any suggestion / help will be appreciate ! 任何建议/帮助将不胜感激!

I couldn't solve this issue. 我无法解决这个问题。

We dropped compass, as it is no longer needed for our needs. 我们放弃了指南针,因为它不再需要我们的需求。

We are now using node-sass, and sometime bootstrap, some times post css, etc, etc... 我们现在使用node-sass,有时使用bootstrap,有时候发布css等等...

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

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