gulpfile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const gulp = require('gulp'),
  2. useref = require('gulp-useref'),
  3. gulpif = require('gulp-if'),
  4. terser = require('gulp-terser'),
  5. sass = require('gulp-sass')(require('sass')),
  6. purgecss = require('gulp-purgecss'),
  7. cleanCSS = require('gulp-clean-css'),
  8. htmlmin = require('gulp-htmlmin'),
  9. rename = require("gulp-rename"),
  10. concat = require("gulp-concat"),
  11. browserSync = require('browser-sync').create();
  12. function copy(cb) {
  13. gulp.src('./node_modules/bootstrap/dist/js/bootstrap.bundle.js')
  14. .pipe(gulp.dest('./js/'));
  15. gulp.src('./node_modules/bootstrap/dist/js/bootstrap.bundle.js.map')
  16. .pipe(gulp.dest('./js/'));
  17. gulp.src('./node_modules/bootstrap-icons/font/fonts/*')
  18. .pipe(gulp.dest('./css/_font/'));
  19. gulp.src('./node_modules/jquery/dist/jquery.min.js')
  20. .pipe(gulp.dest('./js/'));
  21. gulp.src('./node_modules/fullcalendar/main.js')
  22. .pipe(rename('fullcalendar.js'))
  23. .pipe(gulp.dest('./js/', { overwrite:true } ));
  24. gulp.src('./node_modules/fullcalendar/main.css')
  25. .pipe(rename('fullcalendar.css'))
  26. .pipe(gulp.dest('./css/', { overwrite:true } ));
  27. gulp.src('./node_modules/waypoints/lib/noframework.waypoints.js')
  28. .pipe(rename('waypoints.js'))
  29. .pipe(gulp.dest('./js/'));
  30. gulp.src('./node_modules/waypoints/lib/shortcuts/inview.js')
  31. .pipe(rename('waypoints-inview.js'))
  32. .pipe(gulp.dest('./js/'));
  33. console.log("files πŸ“„ from npm pkgs ");
  34. cb();
  35. }
  36. function assets(cb) {
  37. gulp.src('./img/**/*.*')
  38. .pipe(gulp.dest('./app/img/'));
  39. gulp.src('./fonts/**/*.*')
  40. .pipe(gulp.dest('./app/fonts/'));
  41. console.log("moved assets πŸ–ΌοΈ to app/ ");
  42. cb();
  43. }
  44. function html(cb) {
  45. return gulp.src('./app/index.html')
  46. .pipe(htmlmin({
  47. collapseWhitespace: true,
  48. removeComments:true
  49. }))
  50. .pipe(gulp.dest('./app/index.min.html'));
  51. console.log("HTMLmin πŸ—œοΈfor app/ ");
  52. cb();
  53. }
  54. function build(cb) {
  55. gulp.src('index.html')
  56. .pipe(useref())
  57. .pipe(gulpif('*.js', terser({ output: {comments: false} })))
  58. .pipe(gulpif('*.css', purgecss({content:['./app/index.html'],safelist:{deep:[/^fc/]}})))
  59. /* Used Regex here to identify the js elements from the calendar and waypoints */
  60. .pipe(gulpif('*.css', cleanCSS({level: {1: {specialComments: 0}}})))
  61. .pipe(gulp.dest('./app/'));
  62. console.log("Code built πŸ”§ for app/ ");
  63. cb();
  64. }
  65. function mixin(cb) {
  66. return gulp.src('./css/**/*.scss')
  67. .pipe(sass().on('error',sass.logError))
  68. .pipe(gulp.dest('./css/'))
  69. .pipe(browserSync.stream());
  70. console.log("Mixin 🎨");
  71. cb();
  72. }
  73. function reload(cb) {
  74. browserSync.reload();
  75. cb();
  76. }
  77. function run() {
  78. browserSync.init({
  79. server: {
  80. baseDir: "./",
  81. index: "/index.html"
  82. }
  83. });
  84. gulp.watch('./css/*.scss', mixin);
  85. gulp.watch('./css/**/*.css').on('change', gulp.series(build,reload));
  86. gulp.watch('./*.html').on('change', gulp.series(html,build,reload));
  87. gulp.watch('./js/**/*.js').on('change', gulp.series(build,reload));
  88. }
  89. exports.copy = copy;
  90. exports.assets = assets;
  91. exports.html = html;
  92. exports.build = build;
  93. exports.mixin = mixin;
  94. exports.run = run;