Created
August 5, 2014 13:54
-
-
Save brunoksato/82139ad616ca960fd5d4 to your computer and use it in GitHub Desktop.
sem browserfy
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
/** | |
* Created by Bruno Sato on 04/08/2014. | |
*/ | |
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
minifyhtml = require("gulp-minify-html"), | |
imagemin = require('gulp-imagemin'), | |
rename = require('gulp-rename'), | |
minifycss = require('gulp-minify-css'), | |
jshint = require('gulp-jshint'), | |
concat = require('gulp-concat'), | |
clean = require('gulp-clean'), | |
inject = require("gulp-inject"), | |
sass = require('gulp-sass'), | |
uglify = require('gulp-uglify'), | |
cache = require('gulp-cache'), | |
files = require('bower-files')(), | |
autoprefixer = require('gulp-autoprefixer'); | |
// Modules for webserver and livereload | |
var embedlr = require('gulp-embedlr'), | |
refresh = require('gulp-livereload'), | |
lrserver = require('tiny-lr')(), | |
express = require('express'), | |
livereload = require('connect-livereload'), | |
livereloadport = 35729, | |
serverport = 5000; | |
var server = express(); | |
server.use(livereload({port: livereloadport})); | |
server.use(express.static('dist')); | |
server.all('/*', function(req, res) { | |
res.sendfile('index.html', { root: 'dist' }); | |
}); | |
// Dev task | |
gulp.task('dev', ['views', 'bower', 'styles', 'scripts', 'lint'], function() { | |
// Start webserver | |
server.listen(serverport); | |
// Start live reload | |
lrserver.listen(livereloadport); | |
// Run the watch task, to keep taps on changes | |
gulp.run('watch'); | |
}); | |
// JSHint task | |
gulp.task('lint', function() { | |
gulp.src('src/scripts/content/**/*.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')); | |
}); | |
// Styles task | |
gulp.task('styles', function() { | |
gulp.src('src/content/styles/**/*.css') | |
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) | |
.pipe(rename("bundler.min.css")) | |
.pipe(minifycss()) | |
.pipe(gulp.dest('dist/css/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('styles-vendor', function() { | |
gulp.src('bower_components/bootstrap/dist/css/bootstrap.min.css') | |
.pipe(rename("lib.min.css")) | |
.pipe(gulp.dest('dist/css/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('scripts', function() { | |
return gulp.src(['src/scripts/*.js', 'src/scripts/**/*.js']) | |
.pipe(concat('bundler.min.js')) | |
// .pipe(uglify({preserveComments: "some"})) | |
.pipe(gulp.dest('dist/js/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('bower', ['angular', 'angular-cookies', 'angular-ui-router', 'jquery', 'styles-vendor'], function () { | |
console.log('bower task complete', new Date()); | |
}); | |
gulp.task('angular', function() { | |
gulp.src('bower_components/angular/angular.min.js') | |
.pipe(concat("angular.min.js")) | |
.pipe(gulp.dest('dist/js/vendor/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('angular-cookies', function() { | |
gulp.src('bower_components/angular-cookies/angular-cookies.min.js') | |
.pipe(concat("angular-cookies.min.js")) | |
.pipe(gulp.dest('dist/js/vendor/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('angular-ui-router', function() { | |
gulp.src('bower_components/angular-ui-router/release/angular-ui-router.min.js') | |
.pipe(concat("angular-ui-router.min.js")) | |
.pipe(gulp.dest('dist/js/vendor/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('jquery', function() { | |
gulp.src('bower_components/jquery/dist/jquery.min.js') | |
.pipe(concat("jquery.min.js")) | |
.pipe(gulp.dest('dist/js/vendor/')) | |
.pipe(refresh(lrserver)); | |
}); | |
// Views task | |
gulp.task('views', function() { | |
gulp.src('src/index.html') | |
// .pipe(minifyhtml()) | |
.pipe(gulp.dest('dist/')) | |
.pipe(refresh(lrserver)); | |
gulp.src('src/views/**/*') | |
.pipe(minifyhtml()) | |
.pipe(gulp.dest('dist/views/')) | |
.pipe(refresh(lrserver)); | |
}); | |
gulp.task('watch', ['lint'], function() { | |
gulp.watch(['src/scripts/*.js', 'src/scripts/**/*.js'],[ | |
'lint', | |
'scripts' | |
]); | |
gulp.watch(['src/content/styles/**/*.css'], [ | |
'styles' | |
]); | |
gulp.watch(['src/**/*.html'], [ | |
'views' | |
]); | |
}); | |
gulp.task('images', function() { | |
return gulp.src('src/content/images/**/*') | |
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })) | |
.pipe(gulp.dest('dist/img/')) | |
.pipe(livereload(server)); | |
}); | |
gulp.task('clean', function() { | |
return gulp.src(['dist/css/*', 'dist/js/*', 'dist/img/*'], {read: false}) | |
.pipe(clean()); | |
}); | |
gulp.task('inject', function () { | |
var target = gulp.src('dist/index.html'), | |
sources = gulp.src(['dist/css/*.css', 'dist/js/vendor/jquery.min.js', 'dist/js/vendor/angular.min.js', | |
'dist/js/vendor/angular-cookies.min.js', 'dist/js/vendor/angular-ui-router.min.js', | |
'dist/js/*.js', 'dist/js/vendor/*.js'] , {read: false}); | |
return target.pipe(inject(sources)) | |
.pipe(gulp.dest('dist')); | |
// .pipe(gulp.dest('src/')); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment