Sass --watch not recompiling

大兔子大兔子 提交于 2019-12-10 14:53:04

问题


Sass updates my main stylesheet build.css when I save changes to build.scss, but will not update build.css when I save changes to any partials, for example _grid-settings.scss. I essentially have to manually re-save build.scss each time I make a change to a partial in order for Sass to detect a change.

From my terminal:

Justins-MacBook-Air:ageneralist justinbrown$ sass --watch stylesheets:stylesheets
>>> Sass is watching for changes. Press Ctrl-C to stop.
  write stylesheets/build.css
[Listen warning]:
  Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback.

My directory is:

stylesheets/
├── base
│   └── _base.scss
├── build.css
├── build.scss
├── layout
│   └── _layout.scss
└── vendor
    ├── _grid-settings.scss
    ├── bourbon
    ├── highlight
    └── neat

I'm using:

  • Sass 3.3.8.
  • Ruby 2.0.0-p353
  • OSX 10.9

I've looked through several SO posts on issues with sass --watch but none have helped yet to guide me to a solution.

EDIT: I'm adding my build.scss here just in case that's the issue:

@import "vendor/bourbon/bourbon";
@import "vendor/grid-settings";
@import "vendor/neat/neat";
@import "base/base";
@import "layout/layout";

回答1:


I had the same issue.

I managed to fix it by deleting the SASS cache directory. I also ran sudo gem update to update all gems on my system.

I'm not sure which of these things fixed it or if it was a combination of the two.




回答2:


This isn't a satisfactory answer for me, but I ended up trying out another gem that would handle preprocessing, guard-livereload, and though it itself didn't work, when I came back to try sass --watch sass properly monitored my stylesheets directory for changes (partials included) and subsequently recompiled build.scss.

I'm not certain why it works now, but am guessing one of the gems installed along with guard or guard-livereload solved the issue. Perhaps listen or fssm?




回答3:


I had also stuck to the problem of Sass seemed wasn`t watching all file changes correctly.

Sass can`t watch changes in files that are located by the path directing upwards the watching file. For example:

Variant A (Which I had)

scss/
├── base
│   └── controller1.scss
├── utils
│   └── utils.scss
└── app
    └── app.scss

Where app.scss is:

@import '../base/container1'
@import '../utils/utils'

compiling

sass --watch app/app.scss:../css/styles.css

sass --watch app:../css

In both cases sass tracks only app.scss file changes, but not controller1.scss or utils.scss

Variant B (solution)

scss/
├── base
│   └── controller1.scss
├── utils
│   └── utils.scss
└── app.scss

Where app.scss:

@import 'base/container1'
@import 'utils/utils'

compiling

sass --watch app.scss:../css/styles.css

Variant C (solution) also works

scss/
├── base
│   └── controller1.scss
├── utils
│   └── utils.scss
└── app.scss

Where app.scss:

@import 'base/container1'

and controller1.scss:

@import '../utils/utils'
// ...


来源:https://stackoverflow.com/questions/24203318/sass-watch-not-recompiling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!