Last active
December 20, 2015 16:39
-
-
Save radiosilence/6162955 to your computer and use it in GitHub Desktop.
Some useful stuff for CoffeeScript/LiveReload, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
{exec} = require 'child_process' | |
util = require 'util' | |
browserify = require 'browserify' | |
colors = require 'colors' | |
UglifyJS = require "uglify-js" | |
mold = require 'mold-source-map' | |
path = require 'path' | |
jsRoot = path.join(__dirname) | |
bundleBase = 'hodor' | |
bundlePath = "#{bundleBase}.js" | |
mapFilePath = "#{bundlePath}.map" | |
bundleMinPath = "#{bundleBase}.min.js" | |
mapFileMinPath = "#{bundleMinPath}.map" | |
bundle = (cb) -> | |
b = browserify() | |
b.transform('coffeeify') | |
b.add "./#{bundleBase}.coffee" | |
b.bundle | |
debug: true | |
.on('error', (error) -> | |
util.error "#{error}".red) | |
.pipe(fs.createWriteStream(bundlePath)) | |
.on('finish', cb) | |
minify = -> | |
minified = UglifyJS.minify bundlePath, | |
warnings: false | |
mangle: true | |
compress: true | |
fs.writeFile bundleMinPath, minified.code | |
task 'debug', 'Prepare project for distribution.', -> | |
bundle(->) | |
task 'build', 'Compress JavaScript to save size', -> | |
bundle minify | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from livereload.task import Task | |
from livereload.compiler import shell | |
def scssc(path, output, mode='w'): | |
import functools | |
from livereload.compiler import CommandCompiler | |
_compile = CommandCompiler(path) | |
_compile.init_command('sass -f -t compact --scss') | |
return functools.partial(_compile, output, mode) | |
Task.add('*.html') | |
Task.add('*.coffee', shell('cake debug')) | |
Task.add('hodor.scss', scssc('hodor.scss', 'hodor.css')) | |
Task.add('hodor-desktop.scss', scssc('hodor-desktop.scss', 'hodor-desktop.css')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment