Advertisement
Guest User

Untitled

a guest
May 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <binding ProjectOpened='watch' />
  2. "use strict";
  3.  
  4. var gulp = require('gulp'),
  5.     rimraf = require('rimraf'),
  6.     debug = require('gulp-debug'),
  7.     watch = require('gulp-watch'),
  8.     sass = require('gulp-sass'),
  9.     cssmin = require('gulp-cssmin'),
  10.     imagemin = require('gulp-imagemin'),    
  11.     autoprefixer = require('gulp-autoprefixer'),
  12.     uglify = require('gulp-uglify');
  13.  
  14. var paths = {
  15.     webroot: "wwwroot/",
  16.     assets: "Assets/"
  17. };
  18.  
  19. paths.js = paths.assets + "js/**/*.js";
  20. paths.css = paths.assets + "css/**/*.scss";
  21. paths.img = paths.assets + "images/**/*";
  22.  
  23. paths.jsDest = paths.webroot + "js/";
  24. paths.cssDest = paths.webroot + "css/";
  25. paths.imgDest = paths.webroot + "images/";
  26.  
  27. paths.jsMin = paths.webroot + "js/**/*.min.js";
  28. paths.cssMin = paths.webroot + "css/**/*.min.css";
  29. paths.imgMin = paths.webroot + "images/**/*";
  30.  
  31. gulp.task("clean:js", function (callback) {
  32.     rimraf(paths.jsMin, callback);
  33. });
  34.  
  35. gulp.task("clean:css", function (callback) {
  36.     rimraf(paths.cssMin, callback);
  37. });
  38.  
  39. gulp.task("clean:img", function (callback) {
  40.     rimraf(paths.imgMin, callback);
  41. });
  42.  
  43. gulp.task("clean", ["clean:js", "clean:css", "clean:img"]);
  44.  
  45. gulp.task("min:js", function () {
  46.     return gulp.src(paths.js,  { base: "./Assets/js/" })
  47.         .pipe(debug())        
  48.         .pipe(uglify())
  49.         .on("error", (e) => {
  50.             console.error("There was a problem compiling the js files,");
  51.             console.error(e);
  52.         })
  53.         .pipe(gulp.dest(paths.jsDest));
  54. });
  55.  
  56. gulp.task("min:css", function () {
  57.     return gulp.src(paths.css, { base: "./Assets/css/" })
  58.         .pipe(debug())
  59.         .pipe(sass())
  60.         .on("error", (e) => {
  61.             console.error("There was a problem compiling the sass files");
  62.             console.error(e);
  63.         })
  64.         .pipe(cssmin())
  65.         .pipe(autoprefixer({
  66.             browsers: ['last 2 versions'],
  67.             cascade: false
  68.         }))
  69.         .pipe(gulp.dest(paths.cssDest));
  70. });
  71.  
  72. gulp.task("min:img", function () {
  73.     return gulp.src(paths.img, { base: "./Assets/images/" })
  74.         .pipe(debug())
  75.         .pipe(imagemin())
  76.         .on("error", (e) => {
  77.             console.error("There was a problem minifying the images");
  78.             console.error(e);
  79.         })
  80.         .pipe(gulp.dest(paths.imgDest));
  81. });
  82.  
  83. gulp.task("min", ["min:js", "min:css", "min:img"]);
  84.  
  85. gulp.task("watch", function () {
  86.     gulp.watch(paths.js, ["min:js"]);
  87.     gulp.watch(paths.css, ["min:css"]);
  88.     gulp.watch(paths.img, ["min:img"]);
  89. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement