Created
November 18, 2015 10:26
-
-
Save anjum121/288209af989de3237c7f to your computer and use it in GitHub Desktop.
Base gulp setup for
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'), | |
browserSync = require('browser-sync').create(), | |
reload = browserSync.reload, | |
concat = require('gulp-concat'), | |
cssmin = require('gulp-minify-css'), | |
rename = require('gulp-rename'), | |
sass = require('gulp-sass'), | |
uglify = require('gulp-uglify'), | |
jshint = require('gulp-jshint'), | |
order = require("gulp-order"), | |
htmlreplace = require('gulp-html-replace'); | |
var source = { | |
styles: 'app/styles/**/*.scss', | |
js: 'app/js/**/**/*.js', | |
libs: 'libs/**/*.js', | |
html: 'app/js/views/**/*.html', | |
index: 'app/index.html' | |
}; | |
var destination = { | |
styles: 'dist/css', | |
js: 'dist/js', | |
libs: 'dist/libs' | |
}; | |
gulp.task('reload', function () { | |
browserSync.reload(); | |
}); | |
gulp.task('browser-sync', function () { | |
browserSync.init({ | |
/* | |
I like to use a vhost, WAMP guide: https://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp, | |
XAMP guide: http://sawmac.com/xampp/virtualhosts/ | |
*/ | |
// proxy: 'your_dev_site.url' | |
/* For a static server you would use this: */ | |
server: { | |
baseDir: './' | |
} | |
}); | |
}); | |
gulp.task('scripts', function () { | |
return gulp.src(source.js) | |
.pipe(jshint('.jshintrc')) | |
.pipe(jshint.reporter('jshint-stylish')); | |
}); | |
gulp.task('styles', function () { | |
return gulp.src(source.styles) | |
.pipe(sass({includePaths: ['scss']})) | |
.pipe(gulp.dest('app/styles')) | |
.pipe(reload({stream: true})); | |
}); | |
gulp.task('watch', function () { | |
gulp.watch(source.js, ['scripts', 'reload']); | |
gulp.watch(source.styles, ['styles']); | |
gulp.watch(source.html, ['reload']); | |
}); | |
gulp.task('default', ['scripts', 'styles', 'browser-sync', 'watch']); | |
//for destribution only | |
gulp.task('DistScriptsLibs', function () { | |
return gulp.src(source.libs) | |
.pipe(order([ | |
'libs/jquery.js', | |
'libs/angular.js', | |
'libs/lodash.min.js', | |
'libs/restangular.js', | |
'libs/angular-ui-router.js', | |
'libs/bootstrap.js', | |
"libs/smart-table.js" | |
])) | |
.pipe(concat('bundle.js')) | |
.pipe(rename({ | |
suffix: '.min' | |
})) | |
.pipe(gulp.dest(destination.libs)) | |
}); | |
gulp.task('DistScripts', function () { | |
return gulp.src(source.js) | |
.pipe(concat('app.js')) | |
.pipe(uglify()) | |
.pipe(rename({ | |
suffix: '.min' | |
})) | |
.pipe(gulp.dest(destination.js)) | |
}); | |
gulp.task('DistStyles', function () { | |
return gulp.src(source.styles) | |
.pipe(sass({includePaths: ['scss']})) | |
.pipe(gulp.dest('app/styles')) | |
.pipe(cssmin()) | |
.pipe(rename({ | |
suffix: '.min' | |
})) | |
.pipe(gulp.dest(destination.styles)); | |
}); | |
gulp.task('index', function () { | |
gulp.src(source.index) | |
.pipe(htmlreplace({ | |
'css': 'css/main.min.css', | |
'jsLibs': 'libs/bundle.min.js', | |
'js': 'js/app.min.js' | |
})) | |
.pipe(gulp.dest('dist/')); | |
}); | |
gulp.task('dist', ['DistScriptsLibs', 'DistScripts', 'DistStyles', 'index']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment