【问题标题】:grunt watch - compiles sass but only after watch endsgrunt watch - 编译 sass 但仅在 watch 结束后
【发布时间】:2014-04-04 15:50:15
【问题描述】:

不确定这是否是我的错误或错误配置,但是当使用 grunt 监视一些 sass 文件时,它肯定会监视文件,但仅在我退出监视程序时编译 sass 并更新到目标文件。

这是我的监视节点:

watch: {
    sass : {
        files: [sassPath.scss],
        tasks: ['sass']
    }
}

例如这是当前正在发生的事情:

 1. I do `grunt watch` on the command line
2. Start editing sass files
3. Command line notifies me that the change has been detected and it runs the sass task successfully
4. I manually look at the destination css file - no changes
5. ctrl + c to close the watcher while looking in the destination css file - i can see it updated as soon as the watch closes

我真的希望目标 css 文件在 sass 编译后立即更新

【问题讨论】:

  • 我认为您的 grunt watch:sass 任务没有任何问题。您是否尝试过自己运行它?这不是watch 任务的常见行为,但我必须仔细查看您的Gruntfile.js 以查看是否有其他问题导致问题。尝试更新您的本地 grunt 和相关依赖项(watchsass)。

标签: sass gruntjs grunt-contrib-watch


【解决方案1】:

是的,某个更新中似乎存在一个错误,导致您的 gruntfile.js 无法工作,我遇到了同样的问题,在通过 composer 更新后的一天,文件刚刚停止工作,我不得不将 watch 部分更改为看起来像这样并修复它:

        // Watch for files and folder changes
    watch: {
        sass: {
            files: ['<%= options.sass.base %>/{,*/}*.{scss,sass}'],
            tasks: ['sass']
        },
        livereload: {
            options: {
                livereload: 35729,
            },
            files: [
                'app/views/*/*.php',
                '{tmp/<%= options.css.base %>,<%= options.css.base %>}/{,*/}*.css',
                '{tmp/<%= options.js.base %>,<%= options.js.base %>}/{,*/}*.js',
                '{tmp/<%= options.sass.base %>,<%= options.sass.base %>}/{,*/}*.css',
            ]
        },
        options: {
            livereload: true
        },
        files: '<%= options.watch.files %>',
        tasks: ['default', 'notify:watch']
    }

【讨论】:

  • 他的配置没有任何问题——就他的描述和代码而言。但是如果不看他的Gruntfile.js,就不可能知道一切是否正常。有人当然可能会欣赏您对 watch 任务的方法,但我认为这个答案并没有为他所描述的问题增加太多价值(就像在撰写本文时一样)......因为你基本上是在做他也一样,花里胡哨。 :) 和平。
  • @WallaceSidhrée 是的,这个花里胡哨是对我已经在 github 上报告的错误的临时修复。我应该提到这一点!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-03
  • 2014-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-21
相关资源
最近更新 更多