Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't exclude partials from being build on save. #45

Open
pawel-dabek opened this issue Mar 13, 2022 · 9 comments
Open

Can't exclude partials from being build on save. #45

pawel-dabek opened this issue Mar 13, 2022 · 9 comments

Comments

@pawel-dabek
Copy link

I have already tried this setting:

"filename_filter": "(/|\\\\|^)(?!_)(\\w+)\\.(css|js|sass|less|scss)$",

but this makes all files to not build at all. I'm using Sublime Text 4 with newest dart sass and SASS build plugin. Any ideas What I might be doing wrong?

@PhoenixIV
Copy link

PhoenixIV commented Mar 31, 2022

Damn thanks for you comment. I did not even know there was a pre-definition for "partials" file names. I just built a "exclude .inc.scss" filter on my own. (Spend an hour reading the docs? NAH. Spend two days hunting for errors? YAY)

This was the filter I used to exclude .inc.... files: (?<!\\.inc)\\.(sass|less|scss)$

There used to be a filter for _ in this project: cb08398
but that one is faulty: It will not trigger builds even if the _ is in the middle of the file_name.scss

I played around with this for quite some time now and did not yet find out why
^[^_].*\\.(css|js|sass|less|scss)$ does not work. I have no idea. It does in my regex testing tool.

I will give up for now but wanted to leave you with my findings so far.

@alexnj
Copy link
Owner

alexnj commented Mar 31, 2022

This likely is a matter of tweaking the regex pattern, or may be we need to make this a list of patterns than just having to overload everything to one field. I can look into this — in order to reproduce this on my side, what patterns are you trying to exclude?

@PhoenixIV
Copy link

PhoenixIV commented Mar 31, 2022

@paweuek is looking to exclude all files starting with _

@PhoenixIV
Copy link

PhoenixIV commented Mar 31, 2022

However I want to mention that it is quite smart as mentioned in #44 to still trigger a build process even when editing partials. This must then be tweaked in the building tool (rebuild all files).

@pawel-dabek
Copy link
Author

@alexnj @PhoenixIV I've managed to fix my issue by adding the code from this pull request:
#30
to SublimeOnSaveBuild.py file and then using this new option with sublimeonsavebuild set like that:

{
    "filename_filter": "\\.(scss)$",
    "filename_ignore" : "^_+",
    "build_on_save": 1
} 

later on I learned that I can watch my main scss file with dart sass so I don't really need to build on save ;__;

@alexnj
Copy link
Owner

alexnj commented Mar 31, 2022

@PhoenixIV I'm in agreement with you that a partial stylesheet file update should result in a build of the CSS bundle. The build step should point towards the CSS build command, and it would pick up the modified partials file. This is one of the workflows possible. I'm curious when would we modify an include file but not want an associated build-artifact be updated? @paweuek sounds like you are attempting to do something similar, so would be good to know.

@paweuek yes, file watchers are an alternative pattern to this if the tradeoffs work for your specific workflow (i.e., having to start and maintain a parallel run process, inotify limits, memory and cpu usage on watching, etc.). Both are useful patterns!

Regardless of the workflow (which can vary developer to developer, runtime etc.), the plugin should allow you to define a pattern by which a build command can be are triggered, when the file being saved matches the pattern. Thus by definition you should be able to exclude some files/patterns from it. This is currently achieved through a single regular expression pattern, but if it doesn't scale to your needs, we can and should enhance the field.

@PhoenixIV
Copy link

PhoenixIV commented Apr 1, 2022

The 'filename_ignore' option (#30) is something I currently question, as the existing regex for positive matching (should) already allow full control. Not saying it might not make things easier.

Out of curiosity: If anyone knows why my pattern ^[^_].*\\.(css|js|sass|less|scss)$ does not work, please describe it to me. I have it working in my regex sandbox...

Edit: It came to me right after this message and I can confirm: My pattern did not work because it is matched against the full path of the file, not just the filename!

@alexnj well thought reply

@PhoenixIV
Copy link

I now created a working filename_filter that ignores files starting with _
"(/|\\\\|^)(?!_)[^\\\\/]*\\.(css|js|sass|less|scss)$"

Please note you may prefer rebuilding all files when editing partials, though (a message to those only reading this post detached from the previous)

@PhoenixIV
Copy link

I created a build system that will update all affected files:

{
    "cmd": ["sass", "--update", "${file_path}:${file_path}/../css/", "--stop-on-error"],
    // assumes a separate directory for output files called "css"

    "osx":
    {
        "path": "/user/local/bin:$PATH"
    },

    "windows":
    {
        "shell": true
    }
}

It will only rebuild files that are affected by changes made (because of the --update parameter).

This requires this package's filename_filter to be the current default / trigger also for partials (files starting with _). The sass compiler is programmed in a way that it will not compile files in a directory starting with _ anyway.

As mentioned by @alexnj you might prefer this over watching a directory constantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants