SHARE
TWEET

Untitled

a guest Feb 27th, 2020 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { watch, series, parallel, src, dest } = require('gulp');
  2. const sass = require('gulp-sass');
  3. const clean = require('gulp-clean');
  4. const pug = require('gulp-pug');
  5. const concat = require('gulp-concat');
  6. const autoprefixer = require('gulp-autoprefixer');
  7. const browsersync = require('browser-sync').create();
  8. //const cssnano = require('gulp-cssnano');
  9. const uglify = require('gulp-uglify');
  10. //const imagemin = require('gulp-imagemin');
  11. //const htmlmin = require('gulp-htmlmin');
  12.  
  13. function clean_app(cb) {
  14.   src('./app', { allowEmpty: true }, {
  15.       read: false
  16.     })
  17.     .pipe(clean());
  18.   cb();
  19. }
  20.  
  21. function clean_build(cb) {
  22.   src('./build', { allowEmpty: true }, {
  23.       read: false
  24.     })
  25.     .pipe(clean());
  26.   cb();
  27. }
  28.  
  29. function styles(cb) {
  30.   src([
  31.     './src/styles/application.scss',
  32.     ])
  33.     .pipe(sass())
  34.     .pipe(concat('build.css'))
  35.     .pipe(dest('./app/css'))
  36.     .pipe(browsersync.stream());
  37.   cb();
  38. }
  39.  
  40. function styles_build(cb) {
  41.   src([
  42.     './src/styles/application.scss',
  43.     ])
  44.     .pipe(sass())
  45.     .pipe(autoprefixer({
  46.       browsers: ['last 2 versions'],
  47.       cascade: false
  48.     }))
  49.     .pipe(concat('build.css'))
  50.     //.pipe(cssnano())
  51.     .pipe(dest('./build/css'));
  52.   cb();
  53. }
  54.  
  55. function scripts(cb) {
  56.   src([
  57.     'node_modules/jquery/dist/jquery.min.js',
  58.     'node_modules/gsap/src/minified/TweenMax.min.js',
  59.     'node_modules/gsap/src/minified/TimelineMax.min.js',
  60.     'node_modules/gsap/src/minified/easing/EasePack.min.js',
  61.     'node_modules/gsap/src/minified/plugins/ScrollToPlugin.min.js',
  62.     'node_modules/scrollmagic/scrollmagic/minified/ScrollMagic.min.js',
  63.     'node_modules/scrollmagic/scrollmagic/minified/plugins/animation.gsap.min.js',
  64.     'node_modules/scrollmagic/scrollmagic/minified/plugins/debug.addIndicators.min.js',
  65.     './src/scripts/**/*.js'
  66.     ])
  67.     .pipe(concat('build.js'))
  68.     .pipe(dest('./app/js'))
  69.     .pipe(browsersync.stream());
  70.   cb();
  71. }
  72.  
  73. function scripts_build(cb) {
  74.   src([
  75.     'node_modules/jquery/dist/jquery.min.js',
  76.     'node_modules/gsap/src/minified/TweenMax.min.js',
  77.     'node_modules/gsap/src/minified/TimelineMax.min.js',
  78.     'node_modules/gsap/src/minified/easing/EasePack.min.js',
  79.     'node_modules/gsap/src/minified/plugins/ScrollToPlugin.min.js',
  80.     'node_modules/scrollmagic/scrollmagic/minified/ScrollMagic.min.js',
  81.     'node_modules/scrollmagic/scrollmagic/minified/plugins/animation.gsap.min.js',
  82.     'node_modules/scrollmagic/scrollmagic/minified/plugins/debug.addIndicators.min.js',
  83.     './src/scripts/**/*.js'
  84.     ])
  85.     .pipe(uglify())
  86.      .pipe(concat('build.js'))
  87.     .pipe(dest('./build/js'));
  88.   cb();
  89. }
  90.  
  91.  
  92. function images(cb) {
  93.   src('./src/images/**/*.{gif,jpg,png,svg}')
  94.     .pipe(dest('./app/img'))
  95.     .pipe(browsersync.stream());
  96.   cb();
  97. }
  98.  
  99. function images_build(cb) {
  100.   src('./src/images/**/*.{gif,jpg,png,svg}')
  101.     //.pipe(imagemin())
  102.     .pipe(dest('./build/img'));
  103.   cb();
  104. }
  105.  
  106.  
  107. function fonts(cb) {
  108.   src('./src/fonts/**/*')
  109.     .pipe(dest('./app/css/fonts'))
  110.     .pipe(browsersync.stream());
  111.   cb();
  112. }
  113.  
  114. function fonts_build(cb) {
  115.   src('./src/fonts/**/*')
  116.     .pipe(dest('./build/css/fonts'));
  117.   cb();
  118. }
  119.  
  120.  
  121. function views(cb) {
  122.   src('./src/views/**/*.pug')
  123.     .pipe(pug({
  124.       pretty: true
  125.     }))
  126.     .pipe(dest('./app'))
  127.     .pipe(browsersync.stream());
  128.   cb();
  129. }
  130.  
  131. function views_build(cb) {
  132.   src('./src/views/**/*.pug')
  133.     .pipe(pug({
  134.       pretty: false
  135.     }))
  136.     // .pipe(htmlmin({
  137.     //   collapseWhitespace: true
  138.     // }))
  139.     .pipe(dest('./build'));
  140.   cb();
  141. }
  142.  
  143.  
  144. function public(cb) {
  145.   src('./src/public/**/*')
  146.     .pipe(dest('./app'))
  147.     .pipe(browsersync.stream());
  148.   cb();
  149. }
  150.  
  151. function public_build(cb) {
  152.   src('./src/public/**/*')
  153.     .pipe(dest('./build'));
  154.   cb();
  155. }
  156.  
  157. function server(cb) {
  158.   browsersync.init({
  159.     server: {
  160.       baseDir: './app'
  161.     }
  162.   });
  163.  
  164.   watch('./src/styles/**/*.scss', styles);
  165.   watch('./src/scripts/**/*.js', scripts);
  166.   watch('./src/images/**/*', images);
  167.   watch('./src/fonts/**/*', fonts);
  168.   watch('./src/views/**/*.pug', views);
  169.   watch('./src/public/**/*', public);
  170.  
  171.   watch('./app/*.html').on('change', browsersync.reload);
  172.   cb();
  173. }
  174.  
  175. exports.clean = clean_app;
  176. exports.build = series(public_build, parallel(styles_build, scripts_build, images_build, fonts_build), views_build);
  177. exports.default = series(public, parallel(styles, scripts, images, fonts), views, server);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top