Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. var gulp = require('gulp'),
  2. gutil = require('gulp-util' ),
  3. sass = require('gulp-sass'),
  4. browserSync = require('browser-sync'),
  5. concat = require('gulp-concat'),
  6. uglify = require('gulp-uglify'),
  7. cleanCSS = require('gulp-clean-css'),
  8. rename = require('gulp-rename'),
  9. del = require('del'),
  10. imagemin = require('gulp-imagemin'),
  11. cache = require('gulp-cache'),
  12. autoprefixer = require('gulp-autoprefixer'),
  13. ftp = require('vinyl-ftp'),
  14. notify = require("gulp-notify");
  15.  
  16. // Скрипты проекта
  17.  
  18. gulp.task('common-js', function() {
  19. return gulp.src([
  20. 'app/js/common.js',
  21. ])
  22. .pipe(concat('common.min.js'))
  23. .pipe(uglify())
  24. .pipe(gulp.dest('app/js'));
  25. });
  26.  
  27. gulp.task('js', ['common-js'], function() {
  28. return gulp.src([
  29. 'app/libs/jquery/dist/jquery.min.js',
  30. 'app/libs/jQuery.mmenu/dist/jquery.mmenu.all.min.js',
  31. 'app/js/common.min.js', // Всегда в конце
  32. ])
  33. .pipe(concat('scripts.min.js'))
  34. // .pipe(uglify()) // Минимизировать весь js (на выбор)
  35. .pipe(gulp.dest('app/js'))
  36. .pipe(browserSync.reload({stream: true}));
  37. });
  38.  
  39. gulp.task('browser-sync', function() {
  40. browserSync({
  41. server: {
  42. baseDir: 'app'
  43. },
  44. notify: false,
  45. // tunnel: true,
  46. // tunnel: "projectmane", //Demonstration page: http://projectmane.localtunnel.me
  47. });
  48. });
  49.  
  50. gulp.task('sass', function() {
  51. return gulp.src('app/sass/**/*.sass')
  52. .pipe(sass({outputStyle: 'expand'}).on("error", notify.onError()))
  53. .pipe(rename({suffix: '.min', prefix : ''}))
  54. .pipe(autoprefixer(['last 15 versions']))
  55. .pipe(cleanCSS()) // Опционально, закомментировать при отладке
  56. .pipe(gulp.dest('app/css'))
  57. .pipe(browserSync.reload({stream: true}));
  58. });
  59.  
  60. gulp.task('watch', ['sass', 'js', 'browser-sync'], function() {
  61. gulp.watch('app/sass/**/*.sass', ['sass']);
  62. gulp.watch(['libs/**/*.js', 'app/js/common.js'], ['js']);
  63. gulp.watch('app/*.html', browserSync.reload);
  64. });
  65.  
  66. gulp.task('imagemin', function() {
  67. return gulp.src('app/img/**/*')
  68. .pipe(cache(imagemin()))
  69. .pipe(gulp.dest('dist/img'));
  70. });
  71.  
  72. gulp.task('build', ['removedist', 'imagemin', 'sass', 'js'], function() {
  73.  
  74. var buildFiles = gulp.src([
  75. 'app/*.html',
  76. 'app/.htaccess',
  77. ]).pipe(gulp.dest('dist'));
  78.  
  79. var buildCss = gulp.src([
  80. 'app/css/main.min.css',
  81. ]).pipe(gulp.dest('dist/css'));
  82.  
  83. var buildJs = gulp.src([
  84. 'app/js/scripts.min.js',
  85. ]).pipe(gulp.dest('dist/js'));
  86.  
  87. var buildFonts = gulp.src([
  88. 'app/fonts/**/*',
  89. ]).pipe(gulp.dest('dist/fonts'));
  90.  
  91. });
  92.  
  93. gulp.task('deploy', function() {
  94.  
  95. var conn = ftp.create({
  96. host: 'hostname.com',
  97. user: 'username',
  98. password: 'userpassword',
  99. parallel: 10,
  100. log: gutil.log
  101. });
  102.  
  103. var globs = [
  104. 'dist/**',
  105. 'dist/.htaccess',
  106. ];
  107. return gulp.src(globs, {buffer: false})
  108. .pipe(conn.dest('/path/to/folder/on/server'));
  109.  
  110. });
  111.  
  112. gulp.task('removedist', function() { return del.sync('dist'); });
  113. gulp.task('clearcache', function () { return cache.clearAll(); });
  114.  
  115. gulp.task('default', ['watch']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement