Guest User

Untitled

a guest
May 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var gulp = require('gulp'),
  4. watch = require('gulp-watch'),
  5. prefixer = require('gulp-autoprefixer'),
  6. uglify = require('gulp-uglify'),
  7. sass = require('gulp-sass'),
  8. sourcemaps = require('gulp-sourcemaps'),
  9. rigger = require('gulp-rigger'),
  10. cssmin = require('gulp-minify-css'),
  11. imagemin = require('gulp-imagemin'),
  12. pngquant = require('imagemin-pngquant'),
  13. rimraf = require('rimraf'),
  14. browserSync = require("browser-sync"),
  15. reload = browserSync.reload;
  16.  
  17. var path = {
  18. build: {
  19. html: 'build/',
  20. js: 'build/js/',
  21. css: 'build/css/',
  22. img: 'build/img/',
  23. fonts: 'build/fonts/'
  24. },
  25. src: {
  26. html: 'src/*.html',
  27. js: 'src/js/main.js',
  28. style: 'src/style/main.scss',
  29. img: 'src/img/**/*.*',
  30. fonts: 'src/fonts/**/*.*'
  31. },
  32. watch: {
  33. html: 'src/**/*.html',
  34. js: 'src/js/**/*.js',
  35. style: 'src/style/**/*.scss',
  36. img: 'src/img/**/*.*',
  37. fonts: 'src/fonts/**/*.*'
  38. },
  39. clean: './build'
  40. };
  41.  
  42. var config = {
  43. server: {
  44. baseDir: "./build"
  45. },
  46. tunnel: true,
  47. host: 'localhost',
  48. port: 9000,
  49. logPrefix: "Frontend_Devil"
  50. };
  51.  
  52. gulp.task('webserver', function () {
  53. browserSync(config);
  54. });
  55.  
  56. gulp.task('clean', function (cb) {
  57. rimraf(path.clean, cb);
  58. });
  59.  
  60. gulp.task('html:build', function () {
  61. gulp.src(path.src.html)
  62. .pipe(rigger())
  63. .pipe(gulp.dest(path.build.html))
  64. .pipe(reload({stream: true}));
  65. });
  66.  
  67. gulp.task('js:build', function () {
  68. gulp.src(path.src.js)
  69. .pipe(rigger())
  70. .pipe(sourcemaps.init())
  71. .pipe(uglify())
  72. .pipe(sourcemaps.write())
  73. .pipe(gulp.dest(path.build.js))
  74. .pipe(reload({stream: true}));
  75. });
  76.  
  77. gulp.task('style:build', function () {
  78. gulp.src(path.src.style)
  79. .pipe(sourcemaps.init())
  80. .pipe(sass({
  81. sourceMap: true,
  82. errLogToConsole: true
  83. }))
  84. .pipe(prefixer())
  85. .pipe(cssmin())
  86. .pipe(sourcemaps.write())
  87. .pipe(gulp.dest(path.build.css))
  88. .pipe(reload({stream: true}));
  89. });
  90.  
  91. gulp.task('image:build', function () {
  92. gulp.src(path.src.img)
  93. .pipe(imagemin({
  94. progressive: true,
  95. svgoPlugins: [{removeViewBox: false}],
  96. use: [pngquant()],
  97. interlaced: true
  98. }))
  99. .pipe(gulp.dest(path.build.img))
  100. .pipe(reload({stream: true}));
  101. });
  102.  
  103. gulp.task('fonts:build', function() {
  104. gulp.src(path.src.fonts)
  105. .pipe(gulp.dest(path.build.fonts))
  106. });
  107.  
  108. gulp.task('build', [
  109. 'html:build',
  110. 'js:build',
  111. 'style:build',
  112. 'fonts:build',
  113. 'image:build'
  114. ]);
  115.  
  116.  
  117. gulp.task('watch', function(){
  118. watch([path.watch.html], function(event, cb) {
  119. gulp.start('html:build');
  120. });
  121. watch([path.watch.style], function(event, cb) {
  122. gulp.start('style:build');
  123. });
  124. watch([path.watch.js], function(event, cb) {
  125. gulp.start('js:build');
  126. });
  127. watch([path.watch.img], function(event, cb) {
  128. gulp.start('image:build');
  129. });
  130. watch([path.watch.fonts], function(event, cb) {
  131. gulp.start('fonts:build');
  132. });
  133. });
  134.  
  135.  
  136. gulp.task('default', ['build', 'webserver', 'watch']);
Add Comment
Please, Sign In to add comment