Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const gulp = require('gulp-param')(require('gulp'), process.argv);
  2. const sass = require('gulp-sass');
  3. const concat = require('gulp-concat');
  4. const sourcemaps = require('gulp-sourcemaps');
  5. const postcss = require('gulp-postcss');
  6. const uglify = require('gulp-uglify');
  7. const autoprefixer = require('autoprefixer');
  8. const cssnano = require('cssnano');
  9. const gulpif = require('gulp-if');
  10. const plumber = require('gulp-plumber');
  11. const notify = require('gulp-notify');
  12. const browserSync = require('browser-sync').create();
  13.  
  14. const themePath = 'src/theme';
  15. const assetsPath = 'src/theme/assets';
  16.  
  17. // Settings to define
  18. // where are files are located
  19. const Paths = {
  20.   build: assetsPath + '/build/',
  21.   build_css: assetsPath + '/build/css/',
  22.   sass_source: [
  23.     assetsPath + '/src/scss/*.scss',
  24.     assetsPath + '/src/scss/**/*.scss'
  25.   ],
  26.   sass_entry: assetsPath + '/src/scss/main.scss',
  27.   build_js: assetsPath + '/build/js/',
  28.   js_source: [
  29.     assetsPath + '/vendor/jquery/dist/jquery.js',
  30.     assetsPath + '/src/js/modernizr.js',
  31.     assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.core.js',
  32.     assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.util.*.js',
  33.     assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.accordion.js',
  34.     // assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.dropdown.js',
  35.     // assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.dropdownMenu.js',
  36.     // assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.drilldown.js',
  37.     // assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.responsiveMenu.js',
  38.     // assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.responsiveToggle.js',
  39.     // assetsPath + '/vendor/foundation-sites/dist/plugins/foundation.equalizer.js',
  40.     assetsPath + '/vendor/swiper/dist/js/swiper.jquery.js',
  41.     assetsPath + '/vendor/fancybox/source/jquery.fancybox.js',
  42.     assetsPath + '/src/js/gallery-fancybox.js',
  43.     assetsPath + '/vendor/jquery-mousewheel/jquery.mousewheel.js',
  44.     assetsPath + '/src/js/vertical-slider.js',
  45.     assetsPath + '/src/js/horizontal-slider.js',
  46.     assetsPath + '/src/js/member-single-slider.js',
  47.     assetsPath + '/src/js/cards-slider.js',
  48.     assetsPath + '/src/js/accordion-carousel.js',
  49.     assetsPath + '/src/js/main-nav.js',
  50.     assetsPath + '/src/js/secondary-nav.js',
  51.     assetsPath + '/src/js/parallax.js',
  52.     assetsPath + '/src/js/add-class-on-scroll.js',
  53.     assetsPath + '/src/js/ajax-handlers.js',
  54.     assetsPath + '/src/js/entry.js'
  55.   ],
  56.   fonts_source: [
  57.     assetsPath + '/src/fonts/*',
  58.     assetsPath + '/vendor/font-awesome/fonts/*',
  59.     assetsPath + '/vendor/slick-carousel/slick/fonts/*'
  60.   ],
  61.   build_fonts: assetsPath + '/build/fonts/',
  62.   img_source: [
  63.     assetsPath + '/src/images/*',
  64.     assetsPath + '/src/images/**/*',
  65.     assetsPath + '/vendor/slick-carousel/slick/ajax-loader.gif',
  66.     assetsPath + '/vendor/fancybox/source/*.png',
  67.     assetsPath + '/vendor/fancybox/source/*.gif',
  68.  
  69.   ],
  70.   build_img: assetsPath + '/build/images/',
  71.   php_source: [
  72.     themePath + '/*.php',
  73.     themePath + '/functions/*.php',
  74.     themePath + '/views/*.php',
  75.     themePath + '/views/**/*.php',
  76.   ]
  77. };
  78.  
  79. // Build styles for dev
  80. gulp.task('styles', function (production) {
  81.   var postcssArg = [
  82.     autoprefixer({ browsers: ['> 2%', 'last 2 versions'] })
  83.   ];
  84.  
  85.   if (production) postcssArg.push(cssnano);
  86.  
  87.   return gulp.src(Paths.sass_entry)
  88.     .pipe(plumber({
  89.       errorHandler: notify.onError(function (err) {
  90.         return { title: 'styles', message: err.message };
  91.       })
  92.     }))
  93.     .pipe(gulpif(!production, sourcemaps.init()))
  94.     .pipe(sass())
  95.     .pipe(postcss(postcssArg))
  96.     .pipe(concat('main.css'))
  97.     .pipe(gulpif(!production, sourcemaps.write()))
  98.     .pipe(gulp.dest(Paths.build_css))
  99.     .pipe(browserSync.stream());
  100. });
  101.  
  102. // Build scripts for dev
  103. gulp.task('scripts', function (production) {
  104.   return gulp.src(Paths.js_source)
  105.     .pipe(plumber({
  106.       errorHandler: notify.onError(function (err) {
  107.         return { title: 'scripts', message: err.message };
  108.       })
  109.     }))
  110.     .pipe(gulpif(!production, sourcemaps.init()))
  111.     .pipe(concat('bundle.js'))
  112.     .pipe(gulpif(!production, sourcemaps.write()))
  113.     .pipe(gulpif(production, uglify()))
  114.     .pipe(gulp.dest(Paths.build_js))
  115.     .pipe(browserSync.stream());
  116. });
  117.  
  118. // Copy fonts from given locations
  119. // to the build folder for production
  120. gulp.task('fonts', function () {
  121.   return gulp.src(Paths.fonts_source)
  122.     .pipe(gulp.dest(Paths.build_fonts))
  123.     .pipe(browserSync.stream());
  124. });
  125.  
  126. // Copy images from given locations
  127. // to the build folder for production
  128. gulp.task('images', function () {
  129.   return gulp.src(Paths.img_source)
  130.     // .pipe(imagemin())
  131.     .pipe(gulp.dest(Paths.build_img))
  132.     .pipe(browserSync.stream());
  133. });
  134.  
  135. // Checks if something changes
  136. gulp.task('watch', function (proxy) {
  137.   browserSync.init({
  138.     ui: false,
  139.     open: false,
  140.     files: Paths.php_source,
  141.     proxy,
  142.     logPrefix: 'LOG',
  143.     snippetOptions: {
  144.       whitelist: ['/wp-admin/admin-ajax.php'],
  145.       blacklist: ['/wp-admin/**']
  146.     }
  147.   });
  148.  
  149.   gulp.watch(Paths.sass_source, ['styles']);
  150.   gulp.watch(Paths.js_source, ['scripts']);
  151.   gulp.watch(Paths.fonts_source, ['fonts']);
  152.   gulp.watch(Paths.img_source, ['images']);
  153. });
  154.  
  155. gulp.task('build', ['styles', 'scripts', 'fonts', 'images']);
  156. gulp.task('default', ['build', 'watch']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement