123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var gulp = require('gulp');
  2. var less = require('gulp-less');
  3. var browserSync = require('browser-sync').create();
  4. var header = require('gulp-header');
  5. var cleanCSS = require('gulp-clean-css');
  6. var rename = require("gulp-rename");
  7. var uglify = require('gulp-uglify');
  8. var pkg = require('./package.json');
  9. // Set the banner content
  10. var banner = ['/*!\n',
  11. ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
  12. ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
  13. ' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n',
  14. ' */\n',
  15. ''
  16. ].join('');
  17. // Compile LESS files from /less into /css
  18. gulp.task('less', function() {
  19. return gulp.src('less/sb-admin-2.less')
  20. .pipe(less())
  21. .pipe(header(banner, { pkg: pkg }))
  22. .pipe(gulp.dest('dist/css'))
  23. .pipe(browserSync.reload({
  24. stream: true
  25. }))
  26. });
  27. // Minify compiled CSS
  28. gulp.task('minify-css', ['less'], function() {
  29. return gulp.src('dist/css/sb-admin-2.css')
  30. .pipe(cleanCSS({ compatibility: 'ie8' }))
  31. .pipe(rename({ suffix: '.min' }))
  32. .pipe(gulp.dest('dist/css'))
  33. .pipe(browserSync.reload({
  34. stream: true
  35. }))
  36. });
  37. // Copy JS to dist
  38. gulp.task('js', function() {
  39. return gulp.src(['js/sb-admin-2.js'])
  40. .pipe(header(banner, { pkg: pkg }))
  41. .pipe(gulp.dest('dist/js'))
  42. .pipe(browserSync.reload({
  43. stream: true
  44. }))
  45. })
  46. // Minify JS
  47. gulp.task('minify-js', ['js'], function() {
  48. return gulp.src('js/sb-admin-2.js')
  49. .pipe(uglify())
  50. .pipe(header(banner, { pkg: pkg }))
  51. .pipe(rename({ suffix: '.min' }))
  52. .pipe(gulp.dest('dist/js'))
  53. .pipe(browserSync.reload({
  54. stream: true
  55. }))
  56. });
  57. // Copy vendor libraries from /bower_components into /vendor
  58. gulp.task('copy', function() {
  59. gulp.src(['bower_components/bootstrap/dist/**/*', '!**/npm.js', '!**/bootstrap-theme.*', '!**/*.map'])
  60. .pipe(gulp.dest('vendor/bootstrap'))
  61. gulp.src(['bower_components/bootstrap-social/*.css', 'bower_components/bootstrap-social/*.less', 'bower_components/bootstrap-social/*.scss'])
  62. .pipe(gulp.dest('vendor/bootstrap-social'))
  63. gulp.src(['bower_components/datatables/media/**/*'])
  64. .pipe(gulp.dest('vendor/datatables'))
  65. gulp.src(['bower_components/datatables-plugins/integration/bootstrap/3/*'])
  66. .pipe(gulp.dest('vendor/datatables-plugins'))
  67. gulp.src(['bower_components/datatables-responsive/css/*', 'bower_components/datatables-responsive/js/*'])
  68. .pipe(gulp.dest('vendor/datatables-responsive'))
  69. gulp.src(['bower_components/flot/*.js'])
  70. .pipe(gulp.dest('vendor/flot'))
  71. gulp.src(['bower_components/flot.tooltip/js/*.js'])
  72. .pipe(gulp.dest('vendor/flot-tooltip'))
  73. gulp.src(['bower_components/font-awesome/**/*', '!bower_components/font-awesome/*.json', '!bower_components/font-awesome/.*'])
  74. .pipe(gulp.dest('vendor/font-awesome'))
  75. gulp.src(['bower_components/jquery/dist/jquery.js', 'bower_components/jquery/dist/jquery.min.js'])
  76. .pipe(gulp.dest('vendor/jquery'))
  77. gulp.src(['bower_components/metisMenu/dist/*'])
  78. .pipe(gulp.dest('vendor/metisMenu'))
  79. gulp.src(['bower_components/morrisjs/*.js', 'bower_components/morrisjs/*.css', '!bower_components/morrisjs/Gruntfile.js'])
  80. .pipe(gulp.dest('vendor/morrisjs'))
  81. gulp.src(['bower_components/raphael/raphael.js', 'bower_components/raphael/raphael.min.js'])
  82. .pipe(gulp.dest('vendor/raphael'))
  83. })
  84. // Run everything
  85. gulp.task('default', ['minify-css', 'minify-js', 'copy']);
  86. // Configure the browserSync task
  87. gulp.task('browserSync', function() {
  88. browserSync.init({
  89. server: {
  90. baseDir: ''
  91. },
  92. })
  93. })
  94. // Dev task with browserSync
  95. gulp.task('dev', ['browserSync', 'less', 'minify-css', 'js', 'minify-js'], function() {
  96. gulp.watch('less/*.less', ['less']);
  97. gulp.watch('dist/css/*.css', ['minify-css']);
  98. gulp.watch('js/*.js', ['minify-js']);
  99. // Reloads the browser whenever HTML or JS files change
  100. gulp.watch('pages/*.html', browserSync.reload);
  101. gulp.watch('dist/js/*.js', browserSync.reload);
  102. });