brunch / stylus-brunch

Adds Stylus support to Brunch
MIT License
21 stars 2 forks source link

Listen for changes in partials #34

Closed jsonmaur closed 9 years ago

jsonmaur commented 9 years ago

My Stylus setup consists of several partials imported into a main app.styl. This is to maintain control over import order, and to create access to global variables (ex. for colors). Is there a way for Brunch to listen to those partial files (which begin with an underscore) for changes, and re-compile when they are changed? As of right now, I have to manually rebuild every time I make a style change in a partial.

File structure example:
_modules/
    colors.styl
    fonts.styl
_elements/
    buttons.styl
    inputs.styl
app.styl
_modules/colors.styl
clr_light_gray = rgb(245, 245, 245)
clr_dark_gray = rgb(53, 60, 67)
clr_blue_gray = rgb(107, 118, 128)
...
_elements/buttons.styl
.btn
  background clr_blue_gray
  padding 10px
  ...
app.styl
@import "_modules/colors"
@import "_modules/fonts"
@import "_elements/buttons"
@import "_elements/inputs"
...
es128 commented 9 years ago

Brunch and this plugin already have this behavior. Run brunch in debug mode to gain some insight into what's happening with the dependency resolution.

If you've identified a bug, please open a new issue with the relevant debug info, or even better if possible would be a repo or code that provded a repro case.

jsonmaur commented 9 years ago

Can you provide some insight on how one can get this behavior to work? Is there some flag that needs to be enabled, or what am I missing? Running Brunch in debug mode, you can see that when app.styl is changed, the pipeline runs the compiler. If a partial is changed, in this case _partials/header.styl, you can see Brunch receives the "change" event, but the pipeline does not run the Stylus compiler.

Debugger

es128 commented 9 years ago

Look for the getDependencies lines to see what dependencies are being detected for app.styl.

The progeny module is used to parse your source files for the @import statements in case you care to try to dig in to what's going wrong in your case.

jsonmaur commented 9 years ago

Looks like the issue may be something to do with Stylus File Globbing. In app.styl, I was using file globbing to import the dependencies (ex. @import "_partials/*"). I changed it to import each partial individually, and now it works, recompiling app.styl whenever a partial is changed. Not sure if this is a problem with progeny, stylus, or stylus-brunch though.

es128 commented 9 years ago

Oh yeah glob patterns are not supported by progeny yet. At the time it was written they weren't in stylus yet either. You made no indication in your initial post you were using them - would have been able to identify the issue immediately if you had.

I'll open a couple issues about it when I get a chance to hopefully solicit PRs, since it's been a while now that I haven't gotten around to adding support.

es128 commented 9 years ago

The most immediate solution for you would be to list every include the way you did in the initial post instead of relying on the glob expansion.

jsonmaur commented 9 years ago

Yeah, my mistake for not mentioning it initially, didn't realize it until later. Thanks for your help.

bigardone commented 8 years ago

Hi! I'm experimenting the same issue but without using glob patterns. I'm using the latest version from master:

{
  ...,
   "stylus-brunch": "github:brunch/stylus-brunch",
  ...,
}

This is how my file structure looks like:

_global/
  settings.styl
  base.styl
  layout.styl
  typography.styl
  forms.styl
app.styl

When I update _global/base.styl this the the debug message I get:

brunch:watch change web/static/css/_global/base.styl +16s
  brunch:list Reading web/static/css/_global/base.styl +0ms
  brunch:write Writing 0/2 files +77ms
05 Apr 06:27:43 - info: compiled in 77ms

I have to actually save app.styl so it gets the changes:

brunch:watch change web/static/css/app.styl +4m
  brunch:list Reading web/static/css/app.styl +0ms
  brunch:pipeline Compiling web/static/css/app.styl @ StylusCompiler +2ms
  brunch:pipeline Dependencies web/static/css/app.styl @ StylusCompiler +126ms
  brunch:list Compiled web/static/css/app.styl +3ms
  brunch:write Writing 1/2 files +75ms
  brunch:generate Concatenating [web/static/css/app.styl] => priv/static/css/app.css +1ms
  brunch:common Writing priv/static/css/app.css +4ms
  brunch:common Writing priv/static/css/app.css.map +2ms
05 Apr 06:31:15 - info: compiled app.styl into app.css in 214ms

I'm a Stylus newbie so I don't really know it it's not working properly or I'm just doing it wrong... any thoughts about this? Thanks in advance!

paulmillr commented 8 years ago

@goshakkk

goshacmd commented 8 years ago

It appears to be a regression from one of the refactorings/optimizations in the brunch core. https://github.com/brunch/brunch/pull/1282 should address that