Skip to content

Instantly share code, notes, and snippets.

@Zenithar
Created April 6, 2012 16:36
Show Gist options
  • Save Zenithar/2321191 to your computer and use it in GitHub Desktop.
Save Zenithar/2321191 to your computer and use it in GitHub Desktop.
CoffeeScript command line extension : comments and output minification
# Quoted in http://ww.zenithar.org/2012/04/06/iced-coffeescript-minification/
# Based on https://github.com/jashkenas/coffee-script/wiki/%5BExtensibility%5D-Hooking-into-the-Command-Line-Compiler
#
# Don't forget to install UglifyJS
# npm install -g uglify-js
#
# CoffeeScript = require 'coffee-script'
CoffeeScript = require 'iced-coffee-script'
{parser, uglify} = require 'uglify-js'
CoffeeScript.on 'success', (task) ->
ast = parser.parse task.output
code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle ast, extra: yes
task.output = """
/**
* My Fancy minified javascript file
* Blah blah blah
* Copyright (c) #{ new Date().getFullYear() } Thibault NORMAND
**/\n
""" + code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment