Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. //first install the dependencies
  2. //npm install gulp jshint gulp-cssmin browser-sync gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev
  3.  
  4. // Include gulp
  5. var gulp = require('gulp');
  6.  
  7. // Include Our Plugins
  8. var jshint = require('gulp-jshint');
  9. var sass = require('gulp-sass');
  10. var concat = require('gulp-concat');
  11. var uglify = require('gulp-uglify');
  12. var rename = require('gulp-rename');
  13. var cssmin = require('gulp-cssmin');
  14. var browserSync = require('browser-sync').create();
  15. var reload = browserSync.reload
  16.  
  17. // Lint Task
  18. gulp.task('lint', function () {
  19. return gulp.src('app/js/*.js')
  20. .pipe(jshint())
  21. .pipe(jshint.reporter('default'));
  22. });
  23.  
  24. // Compile Our Sass
  25. gulp.task('sass', function () {
  26. return gulp.src('app/scss/*.scss')
  27. .pipe(sass())
  28. .pipe(gulp.dest('dist/css'));
  29. });
  30.  
  31. gulp.task('css', function () {
  32. gulp.src(['app/css/*.css'])
  33. .pipe(cssmin())
  34. .pipe(rename({suffix: '.min'}))
  35. .pipe(gulp.dest('dist/css'))
  36. .pipe(reload({stream: true}));
  37. });
  38.  
  39. // Concatenate & Minify JS
  40. gulp.task('scripts', function () {
  41. return gulp.src('app/js/*.js')
  42. .pipe(concat('all.js'))
  43. .pipe(gulp.dest('dist'))
  44. .pipe(rename('all.min.js'))
  45. .pipe(uglify())
  46. .pipe(gulp.dest('dist/js'));
  47. });
  48.  
  49.  
  50. gulp.task('js-watch', ['lint','scripts'], function (done) {
  51. browserSync.reload();
  52. done();
  53. });
  54.  
  55. gulp.task('css-watch', ['css'], function (done) {
  56. browserSync.reload();
  57. done();
  58. });
  59.  
  60. // Static server
  61. gulp.task('serve', function() {
  62. browserSync.init({
  63. server: "./app"
  64. });
  65.  
  66. gulp.watch('app/js/*.js', ['js-watch']);
  67. gulp.watch('app/css/*.css', ['css-watch']);
  68. gulp.watch("app/*.html").on('change', browserSync.reload);
  69. });
  70.  
  71. // Default Task
  72. gulp.task('default', ['serve']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement