Created
March 2, 2014 23:16
-
-
Save Psvensso/9315469 to your computer and use it in GitHub Desktop.
Starting Gulpfile for EmberJS with custom minispade, templating, SASS compillation... worx on my machine...
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
var gulp = require('gulp'), | |
sass = require('gulp-ruby-sass'), | |
autoprefixer = require('gulp-autoprefixer'), | |
minifycss = require('gulp-minify-css'), | |
jshint = require('gulp-jshint'), | |
uglify = require('gulp-uglify'), | |
imagemin = require('gulp-imagemin'), | |
rename = require('gulp-rename'), | |
clean = require('gulp-clean'), | |
concat = require('gulp-concat'), | |
cache = require('gulp-cache'), | |
livereload = require('gulp-livereload'), | |
lr = require('tiny-lr'), | |
es6ModuleTranspiler = require("gulp-es6-module-transpiler"), | |
browserify = require('gulp-browserify'), | |
handlebars = require('gulp-ember-handlebars'), | |
es = require('event-stream'), | |
gutil = require('gulp-util'), | |
extend = require('lodash.assign'), | |
handlebars = require('gulp-ember-handlebars'), | |
server = lr(); | |
var handlebarsSettings = { | |
outputType: 'browser', processName: function (sourceFile) { | |
return sourceFile.split('/').pop().replace('.html', '').replace('_', '/').toLowerCase(); | |
} | |
}; | |
function minispade(data) { | |
//minispade.register('basecomponents/route', function () { }); | |
return es.map(function (file, cb) { | |
var headerText = "minispade.register('" + file.relative.replace('\\', '/').replace('.js', '').toLowerCase() + "', function(){"; | |
var footertext = "});"; | |
file.contents = Buffer.concat([ | |
new Buffer(gutil.template(headerText, extend({file : file}, data))),file.contents,new Buffer(gutil.template(footertext, extend({ file: file }, data))) | |
]); | |
cb(null, file); | |
}); | |
}; | |
gulp.task('templates', function () { | |
return gulp.src(['src/app/**/*.html']) | |
.pipe(handlebars(handlebarsSettings)) | |
.pipe(concat('templates.js')) | |
.pipe(gulp.dest('dist/scripts')); | |
}); | |
gulp.task('templates-prod',['templates'], function () { | |
return gulp.src(['src/app/**/*.html']) | |
.pipe(handlebars(handlebarsSettings)) | |
.pipe(minispade()) | |
.pipe(uglify()) | |
.pipe(concat('templates-min.js')) | |
.pipe(gulp.dest('dist/scripts')); | |
}); | |
gulp.task('scripts', function () { | |
return gulp.src(['src/app/**/*.js','!src/**/*_test.js']) | |
.pipe(minispade()) | |
.pipe(concat('app.js')) | |
.pipe(gulp.dest('dist/scripts')); | |
}); | |
gulp.task('scripts-prod',['scripts'], function () { | |
return gulp.src(['src/app/**/*.js', '!src/**/*_test.js']) | |
.pipe(minispade()) | |
.pipe(uglify()) | |
.pipe(concat('app-min.js')) | |
.pipe(gulp.dest('dist/scripts')); | |
}); | |
gulp.task('sass', function () { | |
return gulp.src('src/sass/*.scss') | |
.pipe(sass({compass: true, cacheLocation: 'temp/'})) | |
.pipe(gulp.dest('dist/content/')); | |
}); | |
gulp.task('sass-prod',['sass'], function () { | |
return gulp.src('src/sass/*.scss') | |
.pipe(sass({ compass: true, cacheLocation: 'temp/', style: 'compressed' })) | |
.pipe(rename({ suffix: '-min' })) | |
.pipe(gulp.dest('dist/content/')); | |
}); | |
gulp.task('clean', function () { | |
return gulp.src(['dist/scripts/*.js', '!dist/scripts/loader.js','temp/', 'dist/content/*.css'], { read: false }) | |
.pipe(clean()); | |
}); | |
gulp.task('default', ['build']); | |
gulp.task('build', ['clean','scripts-prod', 'templates-prod', 'sass-prod']); | |
gulp.task('watch', function () { | |
var scripts = gulp.watch('src/app/**/*.js', ['scripts']); | |
scripts.on('change', function (event) { | |
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); | |
}); | |
var templates = gulp.watch('src/app/**/*.html', ['templates']); | |
templates.on('change', function (event) { | |
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment