gulpfile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var gulp = require('gulp');
  2. var sass = require('gulp-sass');
  3. var header = require('gulp-header');
  4. var cleanCSS = require('gulp-clean-css');
  5. var rename = require("gulp-rename");
  6. var uglify = require('gulp-uglify');
  7. var autoprefixer = require('gulp-autoprefixer');
  8. var pkg = require('./package.json');
  9. var browserSync = require('browser-sync').create();
  10. // Set the banner content
  11. var banner = ['/*!\n',
  12. ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
  13. ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
  14. ' * Licensed under <%= pkg.license %> (https://github.com/BlackrockDigital/<%= pkg.name %>/blob/master/LICENSE)\n',
  15. ' */\n',
  16. '\n'
  17. ].join('');
  18. // Copy third party libraries from /node_modules into /vendor
  19. gulp.task('vendor', function() {
  20. // Bootstrap
  21. gulp.src([
  22. './node_modules/bootstrap/dist/**/*',
  23. '!./node_modules/bootstrap/dist/css/bootstrap-grid*',
  24. '!./node_modules/bootstrap/dist/css/bootstrap-reboot*'
  25. ])
  26. .pipe(gulp.dest('./vendor/bootstrap'))
  27. // Font Awesome
  28. gulp.src([
  29. './node_modules/@fortawesome/**/*',
  30. ])
  31. .pipe(gulp.dest('./vendor'))
  32. // jQuery
  33. gulp.src([
  34. './node_modules/jquery/dist/*',
  35. '!./node_modules/jquery/dist/core.js'
  36. ])
  37. .pipe(gulp.dest('./vendor/jquery'))
  38. // jQuery Easing
  39. gulp.src([
  40. './node_modules/jquery.easing/*.js'
  41. ])
  42. .pipe(gulp.dest('./vendor/jquery-easing'))
  43. // Magnific Popup
  44. gulp.src([
  45. './node_modules/magnific-popup/dist/*'
  46. ])
  47. .pipe(gulp.dest('./vendor/magnific-popup'))
  48. // Scrollreveal
  49. gulp.src([
  50. './node_modules/scrollreveal/dist/*.js'
  51. ])
  52. .pipe(gulp.dest('./vendor/scrollreveal'))
  53. });
  54. // Compile SCSS
  55. gulp.task('css:compile', function() {
  56. return gulp.src('./scss/**/*.scss')
  57. .pipe(sass.sync({
  58. outputStyle: 'expanded'
  59. }).on('error', sass.logError))
  60. .pipe(autoprefixer({
  61. browsers: ['last 2 versions'],
  62. cascade: false
  63. }))
  64. .pipe(header(banner, {
  65. pkg: pkg
  66. }))
  67. .pipe(gulp.dest('./css'))
  68. });
  69. // Minify CSS
  70. gulp.task('css:minify', ['css:compile'], function() {
  71. return gulp.src([
  72. './css/*.css',
  73. '!./css/*.min.css'
  74. ])
  75. .pipe(cleanCSS())
  76. .pipe(rename({
  77. suffix: '.min'
  78. }))
  79. .pipe(gulp.dest('./css'))
  80. .pipe(browserSync.stream());
  81. });
  82. // CSS
  83. gulp.task('css', ['css:compile', 'css:minify']);
  84. // Minify JavaScript
  85. gulp.task('js:minify', function() {
  86. return gulp.src([
  87. './js/*.js',
  88. '!./js/*.min.js'
  89. ])
  90. .pipe(uglify())
  91. .pipe(rename({
  92. suffix: '.min'
  93. }))
  94. .pipe(header(banner, {
  95. pkg: pkg
  96. }))
  97. .pipe(gulp.dest('./js'))
  98. .pipe(browserSync.stream());
  99. });
  100. // JS
  101. gulp.task('js', ['js:minify']);
  102. // Default task
  103. gulp.task('default', ['css', 'js', 'vendor']);
  104. // Configure the browserSync task
  105. gulp.task('browserSync', function() {
  106. browserSync.init({
  107. server: {
  108. baseDir: "./"
  109. }
  110. });
  111. });
  112. // Dev task
  113. gulp.task('dev', ['css', 'js', 'browserSync'], function() {
  114. gulp.watch('./scss/*.scss', ['css']);
  115. gulp.watch('./js/*.js', ['js']);
  116. gulp.watch('./*.html', browserSync.reload);
  117. });