Sublime Text 2 Doesn't Save Built SASS File

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.

Sample Image

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,

  1. Open target file, followed by the command palette. Enter SFTP: Monitor File (Upload on External Save)

  2. Start whatever CLI watch/build utility you prefer, for me, Sass: sass --watch app.scss:app.css

  3. 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...

Sidebar Dialog Option for enabling File Monitoring

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



Leave a reply



Submit