gulpfile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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({
  59. content:['./app/index.html'],
  60. safelist:{
  61. deep:[/^fc/],
  62. standard: [/accordian*/]
  63. },
  64. })))
  65. /* Used Regex here to identify the js elements from the calendar and waypoints */
  66. .pipe(gulpif('*.css', cleanCSS({level: {1: {specialComments: 0}}})))
  67. .pipe(gulp.dest('./app/'));
  68. console.log("Code built 🔧 for app/ ");
  69. cb();
  70. }
  71. function mixin(cb) {
  72. return gulp.src('./css/**/*.scss')
  73. .pipe(sass().on('error',sass.logError))
  74. .pipe(gulp.dest('./css/'))
  75. .pipe(browserSync.stream());
  76. console.log("Mixin 🎨");
  77. cb();
  78. }
  79. function reload(cb) {
  80. browserSync.reload();
  81. cb();
  82. }
  83. function run() {
  84. browserSync.init({
  85. server: {
  86. baseDir: "./",
  87. index: "/index.html"
  88. }
  89. });
  90. gulp.watch('./css/*.scss', mixin);
  91. gulp.watch('./css/**/*.css').on('change', gulp.series(build,reload));
  92. gulp.watch('./*.html').on('change', gulp.series(html,build,reload));
  93. gulp.watch('./js/**/*.js').on('change', gulp.series(build,reload));
  94. }
  95. exports.copy = copy;
  96. exports.assets = assets;
  97. exports.html = html;
  98. exports.build = build;
  99. exports.mixin = mixin;
  100. exports.run = run;