gulpfile.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const gulp = require('gulp'),
  2. concat = require('gulp-concat'),
  3. purgecss = require('gulp-purgecss'),
  4. sourcemaps = require('gulp-sourcemaps'),
  5. sass = require('gulp-sass')(require('sass'));
  6. browserSync = require('browser-sync').create();
  7. function copy(cb) {
  8. //gulp.src([
  9. // './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
  10. // './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js.map'
  11. //])
  12. // .pipe(gulp.dest('./js/'));
  13. //gulp.src([
  14. // './node_modules/bootstrap/dist/css/bootstrap.min.css',
  15. // './node_modules/bootstrap/dist/css/bootstrap.min.css.map',
  16. // './node_modules/bootstrap-icons/font/bootstrap-icons.css'
  17. //])
  18. // .pipe(gulp.dest('./css/'));
  19. gulp.src([
  20. './node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff',
  21. './node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff2',
  22. ])
  23. .pipe(gulp.dest('./css/fonts/'));
  24. console.log("Copy assets ๐Ÿ“ฆ ");
  25. cb();
  26. }
  27. function build(cb) {
  28. gulp.src([
  29. './css/styles.css',
  30. './css/custom.css'
  31. ])
  32. .pipe(concat('site.css'))
  33. .pipe(gulp.dest('./css/'));
  34. gulp.src([
  35. './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
  36. './js/scripts.js'
  37. ])
  38. .pipe(concat('site.js'))
  39. .pipe(sourcemaps.init())
  40. .pipe(sourcemaps.write('.'))
  41. .pipe(gulp.dest('./js/'));
  42. console.log("Assets built ๐Ÿ”ง ");
  43. cb();
  44. }
  45. function purge (cb) {
  46. gulp.src('./css/site.css')
  47. .pipe(purgecss({
  48. content: ['./*.html', './js/*.js']
  49. }))
  50. .pipe(sourcemaps.init())
  51. .pipe(sourcemaps.write('.'))
  52. .pipe(gulp.dest('./css/'));
  53. console.log("CSS purged ๐Ÿงน ");
  54. cb();
  55. }
  56. function clean (cb) {
  57. gulp.src('./css/site.css')
  58. .pipe(cleanCSS({level: {1: {specialComments: 0}}}))
  59. .pipe(gulp.dest('./css/'));
  60. console.log("CSS cleaned ๐Ÿงน ");
  61. cb();
  62. }
  63. function mixin() {
  64. return gulp.src('./css/*.scss', { sourcemaps: true })
  65. .pipe(sass().on('error',sass.logError))
  66. .pipe(gulp.dest('./css/'))
  67. .pipe(browserSync.stream());
  68. }
  69. function reload(cb) {
  70. browserSync.reload();
  71. cb();
  72. }
  73. function run() {
  74. browserSync.init({
  75. server: {
  76. baseDir: "./",
  77. index: "/index.html"
  78. }
  79. });
  80. gulp.watch(['./css/*.scss','./css/styles.css']).on('change', gulp.series(mixin, build));
  81. gulp.watch('./js/scripts.js', gulp.series(build));
  82. gulp.watch('./*.html', reload);
  83. gulp.watch([
  84. './css/site.css',
  85. './js/site.js'
  86. ]).on('change',browserSync.reload);
  87. console.log("๐Ÿ”ฅ Run");
  88. }
  89. exports.copy = copy;
  90. exports.build = build;
  91. exports.purge = purge;
  92. exports.clean = clean;
  93. exports.mixin = mixin;
  94. exports.run = run;