gulpfile.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. cleanCSS = require('gulp-clean-css'),
  7. htmlmin = require('gulp-htmlmin'),
  8. rename = require("gulp-rename"),
  9. concat = require("gulp-concat"),
  10. browserSync = require('browser-sync').create();
  11. function copy(cb) {
  12. gulp.src('./node_modules/bootstrap/dist/js/bootstrap.bundle.js')
  13. .pipe(gulp.dest('./js/'));
  14. gulp.src('./node_modules/bootstrap/dist/js/bootstrap.bundle.js.map')
  15. .pipe(gulp.dest('./js/'));
  16. gulp.src('./node_modules/bootstrap-icons/font/fonts/*')
  17. .pipe(gulp.dest('./css/_font/'));
  18. gulp.src('./node_modules/jquery/dist/jquery.min.js')
  19. .pipe(gulp.dest('./js/'));
  20. gulp.src('./node_modules/fullcalendar/main.js')
  21. .pipe(rename('fullcalendar.js'))
  22. .pipe(gulp.dest('./js/', { overwrite:true } ));
  23. gulp.src('./node_modules/fullcalendar/main.css')
  24. .pipe(rename('fullcalendar.css'))
  25. .pipe(gulp.dest('./css/', { overwrite:true } ));
  26. gulp.src('./node_modules/waypoints/lib/noframework.waypoints.js')
  27. .pipe(rename('waypoints.js'))
  28. .pipe(gulp.dest('./js/'));
  29. gulp.src('./node_modules/waypoints/lib/shortcuts/inview.js')
  30. .pipe(rename('waypoints-inview.js'))
  31. .pipe(gulp.dest('./js/'));
  32. console.log("files 📄 from npm pkgs ");
  33. cb();
  34. }
  35. function build(cb) {
  36. gulp.src('index.html')
  37. .pipe(useref())
  38. .pipe(gulpif('*.js', terser()))
  39. .pipe(gulpif('*.css', cleanCSS({level: {1: {specialComments: 0}}})))
  40. .pipe(gulp.dest('./app/'));
  41. console.log("Assets built 🔧 for 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. cb();
  52. }
  53. function mixin(cb) {
  54. return gulp.src('./css/**/*.scss')
  55. .pipe(sass().on('error',sass.logError))
  56. .pipe(gulp.dest('./css/'))
  57. .pipe(browserSync.stream());
  58. cb();
  59. }
  60. function reload(cb) {
  61. browserSync.reload();
  62. cb();
  63. }
  64. function run() {
  65. browserSync.init({
  66. server: {
  67. baseDir: "./",
  68. index: "/index.html"
  69. }
  70. });
  71. gulp.watch('./css/*.scss', mixin);
  72. gulp.watch('./css/**/*.css').on('change', browserSync.reload);
  73. gulp.watch('./*.html').on('change',browserSync.reload);
  74. gulp.watch('./js/**/*.js').on('change', gulp.series(build, reload));
  75. }
  76. exports.copy = copy;
  77. exports.build = build;
  78. exports.mixin = mixin;
  79. exports.run = run;