Skip to content

Instantly share code, notes, and snippets.

@ManzDev ManzDev/MakeOnSave.py
Last active Aug 29, 2015

Embed
What would you like to do?
Sublime Text 3: Build minified CSS file (with autoprefixer) and JS minified file on save (paths for Windows).
import sublime, sublime_plugin, os
class MakeOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
if view.file_name().endswith('.js'):
folder_name, file_name = os.path.split(view.file_name())
file_name, file_ext = file_name.split('.')
view.window().run_command('exec', {
'cmd': ['node', os.environ['APPDATA'] + '\\npm\\node_modules\\minifier\\index.js', '--no-comments', file_name+'.js', '-o', file_name+'.min.js'],
'working_dir': folder_name
})
sublime.status_message(file_name + ' saved.')
if view.file_name().endswith('.less'):
folder_name, file_name = os.path.split(view.file_name())
file_name, file_ext = file_name.split('.')
view.window().run_command('exec', {
'cmd': ['node', os.environ['APPDATA'] + '\\npm\\node_modules\\less\\bin\\lessc', '-x', file_name+'.less', file_name+'.min.without.autoprefixer.css'],
'working_dir': folder_name
})
view.window().run_command('exec', {
'cmd': ['node', os.environ['APPDATA'] + '\\npm\\node_modules\\autoprefixer\\autoprefixer', file_name+'.min.without.autoprefixer.css', '-o', file_name+'.min.css'],
'working_dir': folder_name
})
sublime.status_message(file_name + ' saved.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.