Skip to content

Instantly share code, notes, and snippets.

@sukima
Created May 13, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukima/b5a2d145a1b34dece7f9 to your computer and use it in GitHub Desktop.
Save sukima/b5a2d145a1b34dece7f9 to your computer and use it in GitHub Desktop.
"use strict"
gulp = require("gulp")
$ = require("gulp-load-plugins")()
gulp.task "styles", ->
gulp.src("app/styles/main.scss")
.pipe($.sass())
.pipe($.autoprefixer("last 1 version"))
.pipe(gulp.dest(".tmp/styles"))
.pipe($.size())
gulp.task "scripts", ->
gulp.src("app/scripts/**/*.coffee")
.pipe($.coffee())
.pipe(gulp.dest(".tmp/scripts"))
gulp.task "html", [
"styles"
"scripts"
], ->
jsFilter = $.filter("**/*.js")
cssFilter = $.filter("**/*.css")
gulp.src("app/*.html")
.pipe($.useref.assets())
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest("dist"))
.pipe($.size())
gulp.task "clean", ->
sources = [
".tmp"
"dist"
]
gulp.src(sources, read: false)
.pipe($.clean())
gulp.task "build", [
"html"
"fonts"
]
gulp.task "default", ["clean"], ->
gulp.start "build"
gulp.task "connect", ->
connect = require("connect")
app = connect().use(require("connect-livereload")(port: 35729)).use(connect.static("app")).use(connect.static(".tmp")).use(connect.directory("app"))
require("http").createServer(app).listen(9000).on "listening", ->
console.log "Started connect web server on http://localhost:9000"
gulp.task "serve", [
"styles"
"scripts"
"connect"
], ->
# is this correct?
require("opn") "http://localhost:9000"
gulp.task "watch", [
"clean"
"serve"
], ->
server = $.livereload()
gulp.watch([
"app/*.html"
".tmp/styles/**/*.css"
".tmp/scripts/**/*.js"
])
.on("change", (file) -> server.changed file.path)
gulp.watch "app/styles/**/*.scss", ["styles"]
gulp.watch "app/scripts/**/*.coffee", ["scripts"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment