gulpfile.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. './js/scripts.js'
  38. ])
  39. .pipe(concat('site.js'))
  40. .pipe(sourcemaps.init())
  41. .pipe(sourcemaps.write('.'))
  42. .pipe(gulp.dest('./js/'));
  43. console.log("Assets built ๐Ÿ”ง ");
  44. cb();
  45. }
  46. function purge (cb) {
  47. gulp.src('./css/site.css')
  48. .pipe(purgecss({
  49. content: ['./*.html', './js/*.js']
  50. }))
  51. .pipe(sourcemaps.init())
  52. .pipe(sourcemaps.write('.'))
  53. .pipe(gulp.dest('./css/'));
  54. console.log("CSS purged ๐Ÿงน ");
  55. cb();
  56. }
  57. function clean (cb) {
  58. gulp.src('./css/site.css')
  59. .pipe(cleanCSS({level: {1: {specialComments: 0}}}))
  60. .pipe(gulp.dest('./css/'));
  61. console.log("CSS cleaned ๐Ÿงน ");
  62. cb();
  63. }
  64. function mixin() {
  65. return gulp.src('./css/*.scss', { sourcemaps: true })
  66. .pipe(sass().on('error',sass.logError))
  67. .pipe(gulp.dest('./css/'))
  68. .pipe(browserSync.stream());
  69. }
  70. function reload(cb) {
  71. browserSync.reload();
  72. cb();
  73. }
  74. function run() {
  75. browserSync.init({
  76. open: 'external',
  77. host: 'gwp.ovid',
  78. proxy: 'https://gwp.ovid',
  79. port: '333',
  80. ssl: {
  81. key: '/opt/homebrew/etc/httpd/ssl/gwp.ovid-key.pem',
  82. cert: '/opt/homebrew/etc/httpd/ssl/gwp.ovid.pem'
  83. }
  84. });
  85. gulp.watch(['./css/*.scss','./css/styles.css']).on('change', gulp.series(mixin, build));
  86. gulp.watch('./js/scripts.js', gulp.series(build));
  87. gulp.watch(['./*.json','./**/*.html','./**/*.php','./**/*.css','./**/*.js' ]).on('change',browserSync.reload);
  88. console.log("๐Ÿ”ฅ Run");
  89. }
  90. exports.copy = copy;
  91. exports.build = build;
  92. exports.purge = purge;
  93. exports.clean = clean;
  94. exports.mixin = mixin;
  95. exports.run = run;