Skip to content

Instantly share code, notes, and snippets.

@ManzDev
Last active August 29, 2015 14:12
Show Gist options
  • Save ManzDev/8a642d6935ba2ec69407 to your computer and use it in GitHub Desktop.
Save ManzDev/8a642d6935ba2ec69407 to your computer and use it in GitHub Desktop.
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