7
votes

Ok, here is what I want:

  1. I write .scss files, not .sass files
  2. On saving the file, I get the corresponding .css file in the same folder

Now there are plenty of SASS plugins on Sublime Text2 but none seems to provide anything beyond syntax highlighting for me.

Any suggestions on how to get auto-compiling working on Sublime Text2.

5
here How to Answer[1], to buils sass in sublime text 2 using Build system [1]: stackoverflow.com/questions/12448546/… - Leonardo Lopez

5 Answers

6
votes

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.

5
votes

You should consider to use build system instead of dedicated plugin of it. It's very simple to do.

http://docs.sublimetext.info/en/latest/file_processing/build_systems.html

Something like this:

{
  "cmd": ["sass","$file"],
  "selector": "source.scss",
  "path": "/usr/local/bin"
}

And just hit ctrl + b t build current file. If you have multiple builds for scss you can select one from build menu (Tools -> Build Systems).

3
votes

You could use SublimeOnSaveBuild plugin. And in plugin filter settings just leave .scss files! It's works for just great!

1
votes

I was looking for a sass/scss compiler plugin for Sublime Test, but I have my source folders separate from my css folders. So, going off the comments left on here I wrote SassBuilder that runs off a config file stored in your source folder. It has also been submitted to the Sublime Package Control repository. Once they pull the request, you can install it from there.

SassBuilder on github

1
votes

Sass Builder is the new plugin which is available in Package Manager of sublime text. This does not require any configuration. Just write your scss and hit cmd + b to compile. Your css file will be generated in the same folder as scss.