gulpfile.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const gulp = require('gulp'),
  2. sass = require('gulp-sass'),
  3. rename = require("gulp-rename"),
  4. concat = require("gulp-concat"),
  5. uglify = require('gulp-uglify'),
  6. cleanCSS = require('gulp-clean-css'),
  7. purgeCSS = require('gulp-purgecss'),
  8. sourcemaps = require('gulp-sourcemaps');
  9. purgeSourcemaps = require('gulp-purge-sourcemaps');
  10. browserSync = require('browser-sync').create();
  11. async function copy() {
  12. gulp.src([
  13. './node_modules/bootstrap/dist/js/bootstrap.bundle.js',
  14. './node_modules/bootstrap/dist/css/bootstrap.css',
  15. './node_modules/bootstrap-icons/font/bootstrap-icons.css'
  16. ])
  17. .pipe(sourcemaps.init({loadMaps: true}))
  18. .pipe(purgeSourcemaps())
  19. .pipe(gulp.dest('./_src/'));
  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("📄 Copied");
  26. }
  27. async function build() {
  28. gulp.src([
  29. './_src/bootstrap.bundle.js'
  30. ])
  31. .pipe(concat('script.js'))
  32. .pipe(uglify())
  33. .pipe(rename('script.min.js'))
  34. .pipe(gulp.dest('./js/'));
  35. gulp.src([
  36. './style.css',
  37. './css/custom.css',
  38. './_src/bootstrap-icons.css'
  39. ])
  40. .pipe(concat('style.css'))
  41. .pipe(cleanCSS({level: {1: {specialComments: 0}}}))
  42. .pipe(rename('style.min.css'))
  43. .pipe(gulp.dest('./css/'));
  44. console.log("🔧 Built");
  45. }
  46. function mixin() {
  47. return gulp.src('./css/*.scss')
  48. .pipe(sass().on('error',sass.logError))
  49. .pipe(gulp.dest('./css/'))
  50. .pipe(browserSync.stream());
  51. }
  52. function run() {
  53. browserSync.init({
  54. injectChanges: true,
  55. proxy: 'https://macs.local/hp',
  56. host: 'a.macs',
  57. open: 'external',
  58. port: 8888,
  59. https: true
  60. });
  61. gulp.watch('./css/*.scss', mixin);
  62. gulp.watch([
  63. './*.css',
  64. './**/*.css',
  65. './**/*.scss',
  66. './**/*.js',
  67. './**/*.php'
  68. ]).on('change', browserSync.reload);
  69. console.log("🔥 Ran");
  70. }
  71. exports.copy = copy;
  72. exports.build = build;
  73. exports.mixin = mixin;
  74. exports.run = run;