Skip to content

Instantly share code, notes, and snippets.

@hideki-a
Last active August 29, 2015 14:14
Show Gist options
  • Save hideki-a/28a77b22fdc631b3f05c to your computer and use it in GitHub Desktop.
Save hideki-a/28a77b22fdc631b3f05c to your computer and use it in GitHub Desktop.
My gulpfile.coffee Early 2015
'use strict';
# Settings
BASEPATH = './htdocs/'
PATHS =
STATIC:
SRC: BASEPATH
SCRIPTS:
SRC: BASEPATH + 'common/js/'
STYLES:
SRC: BASEPATH + '_scss/'
DEST: BASEPATH + 'common/css/'
PORT = '3501'
AUTOPREFIXER_BROWSERS = [
'last 2 versions'
'IE >= 8'
'Firefox ESR'
'Android >= 4.1'
]
# Load Modules
gulp = require 'gulp'
path = require 'path'
plugins = require('gulp-load-plugins')()
browserSync = require 'browser-sync'
reload = browserSync.reload
jshintStylish = require 'jshint-stylish'
# Tasks
gulp.task 'serve', ->
browserSync
server:
baseDir: BASEPATH
port: PORT
browser: "google chrome"
return
gulp.task 'styles', ->
gulp.src(PATHS.STYLES.SRC + '*.scss')
.pipe plugins.sourcemaps.init()
.pipe plugins.sass
onError: (err) ->
plugins.notify().write err
.pipe plugins.autoprefixer
browsers: AUTOPREFIXER_BROWSERS
.pipe plugins.sourcemaps.write('.')
.pipe gulp.dest(PATHS.STYLES.DEST)
gulp.task 'jshint', ->
gulp.src PATHS.SCRIPTS.SRC + '*.js'
.pipe plugins.jshint()
.pipe plugins.jshint.reporter(jshintStylish)
.pipe plugins.notify((file) ->
# http://stackoverflow.com/questions/22787673/gulp-sass-error-with-notify#answer-23115547
if file.jshint.success
# Don't show something if success
return false
errors = file.jshint.results.map((data) ->
if data.error
return '(' + data.error.line + ':' + data.error.character + ') ' + data.error.reason
return
).join('\n')
file.relative + ' (' + file.jshint.results.length + ' errors)\n' + errors
)
gulp.task 'watch', ->
gulp.watch PATHS.STATIC.SRC + '*.html', browserSync.reload
gulp.watch PATHS.STYLES.SRC + '*.scss', ['styles', browserSync.reload]
gulp.watch PATHS.SCRIPTS.SRC + '*.js', ['jshint', browserSync.reload]
return
gulp.task 'default', [
'serve'
'watch'
]
{
"name": "sample",
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Hideki Abe",
"license": "MIT",
"devDependencies": {
"browser-sync": "^2.0.0-rc8",
"coffee-script": "^1.8.0",
"connect": "^3.3.4",
"connect-livereload": "^0.5.2",
"gulp": "^3.8.10",
"gulp-autoprefixer": "^2.1.0",
"gulp-jshint": "^1.9.0",
"gulp-livereload": "^3.5.0",
"gulp-load-plugins": "^0.8.0",
"gulp-notify": "^2.2.0",
"gulp-sass": "^1.3.2",
"gulp-sourcemaps": "^1.3.0",
"jshint-stylish": "^1.0.0",
"serve-static": "^1.8.1",
"tiny-lr": "^0.1.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment