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