Auto compile SCSS files in Sublime Text 2
I didn't find any existing plugins that did this, so here it is:
Assuming you've installed the SCSS plugin from Package Control, you can save this as Packages/User/SCSS.py.
import sublime_plugin
import subprocess
import os
from threading import Thread
def compile(input_file):
output_file = os.path.splitext(input_file)[0] + ".css"
cmd = "sass '{0}':'{1}'".format(input_file, output_file)
subprocess.call(cmd, shell=True)
class SCSS(sublime_plugin.EventListener):
def on_post_save(self, view):
scope = (view.syntax_name(view.sel()[0].b)).split().pop()
if scope == "source.scss":
input_file = view.file_name()
t = Thread(target=compile, args=(input_file,))
t.start()
Of course, this would be better as an official Package Control plugin with user configurable settings (where to save files, on/off, etc), but this meets your requirements and doesn't block the editor.
SASS in Sublime Text - Compile main.scss when saving any @import files
You could use sass
in watch mode, and not have to press ctrl-B at all!
$ sass --watch main.scss:output.css
Sublime SFTP - Upload compiled css when sass file saved
I'll throw my solution into the mix, just in case anyone stumbles on this as I did and wants to stick as close to a solely ST-based workflow as possible. If you're using the SFTP package for ST, there is an option to monitor files for external saves.
Unfortunately, using the ST build system to compile my SASS somehow slipped by SFTP. SASS CLI's watch utility, however, triggers the upload just fine. Once set, presuming the target file remains open, SFTP will upload it after each build.
To recap,
Open target file, followed by the command palette. Enter
SFTP: Monitor File (Upload on External Save)
Start whatever CLI watch/build utility you prefer, for me, Sass:
sass --watch app.scss:app.css
Leave target file open, otherwise the SFTP monitor seems to cease.
Enjoy!
NOTE: You can also enable file monitoring from the sidebar by right clicking on the file you wish to monitor and selecting...
Sublime on Save Build exclude pattern
I assume that this patern should work: ^(?<!_)[a-z-]*\.(sass|less|scss)$
This part: (?<=_)
is called positive lookbehind assertion.
You can do some tests here: https://regex101.com/r/gN8uX1/2
Related Topics
Why Does Shoveling a String into a Hash Cause This Result
Ruby: Sorting 2 Arrays Using Values from One of Them
Prawn Gem: How to Create the .Pdf from an *Existing* File (.Xls)
Rails in Rendering Unnecessary Information
Transfer Db from One Heroku App to Another Faster
Create a Ruby Method That Accepts a Hash of Parameters
Rails Migration Complains About Undefined Method 'Attachment' Using Paperclip
Understanding Ruby Method Parameters Syntax
Sinatra Doesn't Know This Ditty Even When Default Route Is Implemented with Modular Style
Use Some Middleware Only for Specific Rack Website
How to Count the Frequencies of the Letters in User Input