Last active
May 16, 2019 05:59
-
-
Save simme/8931006 to your computer and use it in GitHub Desktop.
Gulp file for an Ember project using bower and browserify.
This file contains 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
// Load Ember into the global scope by requiring it | |
require('ember'); | |
// Go have fun | |
var app = Ember.Application.create(); |
This file contains 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'); | |
var browserify = require('gulp-browserify'); | |
var handlebars = require('gulp-ember-handlebars'); | |
var myth = require('gulp-myth'); | |
var hint = require('gulp-jshint'); | |
var concat = require('gulp-concat'); | |
var cache = require('gulp-cache'); | |
var gif = require('gulp-if'); | |
var uglify = require('gulp-uglify'); | |
var debug = process.env.NODE_ENV !== 'production'; | |
gulp.task('hint', function () { | |
return gulp.src('assets/**/*.js') | |
.pipe(hint()); | |
}); | |
gulp.task('scripts', ['hint', 'templates'], function () { | |
var ember = debug ? 'ember.js' : 'ember.prod.js'; | |
return gulp.src('assets/js/app.js') | |
.pipe(browserify({ | |
debug: debug, | |
shim: { | |
jquery: { | |
path: 'bower_components/jquery/jquery.js', | |
exports: '$' | |
}, | |
handlebars: { | |
path: 'bower_components/handlebars/handlebars.js', | |
exports: 'Handlebars' | |
}, | |
templates: { | |
path: 'builds/templates.js', | |
exports: 'Ember.TEMPLATES' | |
}, | |
ember: { | |
path: 'bower_components/ember/' + ember, | |
exports: 'ember', | |
depends: { | |
handlebars: 'Handlebars', | |
jquery: '$' | |
} | |
}, | |
} | |
})) | |
.on('prebundle', function (bundle) { | |
bundle.add('../../bower_components/ember/' + ember); | |
bundle.add('../../builds/templates.js'); | |
}) | |
.pipe(gif(!debug, uglify())) | |
.pipe(gulp.dest('builds/js')); | |
}); | |
gulp.task('templates', function () { | |
return gulp.src('assets/**/*.hbs') | |
.pipe(cache(handlebars({ | |
outputType: 'cjs', | |
templateRoot: 'assets/templates/', | |
processName: function (name) { | |
name = name.split('/').slice(1).join('/').replace(/\.hbs/, ''); | |
return name; | |
} | |
}))) | |
.pipe(concat('templates.js')) | |
.pipe(gulp.dest('builds')); | |
}); | |
gulp.task('styles', function () { | |
return gulp.src('assets/css/master.css') | |
.pipe(myth()) | |
.pipe(gulp.dest('builds/css')); | |
}); | |
gulp.task('default', ['styles', 'scripts'], function () { }); | |
gulp.task('watch', function () { | |
gulp.watch('assets/**/*.js', ['scripts']); | |
gulp.watch('assets/**/*.hbs', ['scripts']); | |
gulp.watch('assets/**/*.css', ['styles']); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment