xExekut3x

gulpfile.js

Aug 31st, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. var gulp = require('gulp'),
  2. util = require('gulp-util'),
  3. del = require('del'),
  4. concat = require('gulp-concat'),
  5. sourcemaps = require('gulp-sourcemaps'),
  6. changed = require('gulp-changed'),
  7. cached = require('gulp-cached'),
  8. remember = require('gulp-remember'),
  9. newer = require('gulp-newer'),
  10. rev = require('gulp-rev'),
  11. sync = require('browser-sync').create(),
  12. uglify = require('gulp-uglify'),
  13. jshint = require('gulp-jshint'),
  14. prefix = require('gulp-autoprefixer'),
  15. minifycss = require('gulp-minify-css'),
  16. imagemin = require('gulp-imagemin'),
  17. pngquant = require('imagemin-pngquant');
  18.  
  19. var src = {
  20. markup: ['./views/**/*.html'],
  21. scripts: ['./assets/js/**/*.js'],
  22. styles: ['./assets/css/**/*.css'],
  23. images: './assets/img/**/*',
  24. fav: ['./assets/*.ico', './assets/*.png'],
  25. other: ['./assets/*.xml', './assets/*.txt'],
  26. modernizr: './bower_components/modernizer/modernizr.js',
  27. jquery: './bower_components/jquery/dist/jquery.min.js',
  28. normalize: './bower_components/normalize-css/normalize.css'
  29. };
  30.  
  31. var dist = {
  32. scripts: './public/js',
  33. styles: './public/css',
  34. images: './public/img',
  35. root: './public'
  36. }
  37.  
  38. gulp.task('clean', function() {
  39. return del(dist.root);
  40. });
  41.  
  42. gulp.task('markup', function() {
  43. return gulp.src(src.markup)
  44. .pipe(gulp.dest(dist.root));
  45. });
  46.  
  47. gulp.task('modernizr', function() {
  48. return gulp.src(src.modernizr)
  49. .pipe(uglify())
  50. .pipe(gulp.dest(dist.scripts));
  51. });
  52.  
  53. gulp.task('jquery', function() {
  54. return gulp.src(src.jquery)
  55. .pipe(gulp.dest(dist.scripts));
  56. });
  57.  
  58. gulp.task('scripts', function() {
  59. return gulp.src(src.scripts)
  60. //.pipe(changed('public'))
  61. .pipe(jshint())
  62. .pipe(jshint.reporter('jshint-stylish'))
  63. .pipe(jshint.reporter('fail'))
  64. //.pipe(sourcemaps.init())
  65. .pipe(uglify())
  66. .pipe(concat('scripts.js'))
  67. //.pipe(util.env.type === 'production' ? uglify() : util.noop())
  68. //.pipe(sourcemaps.write())
  69. .pipe(gulp.dest(dist.scripts));
  70. });
  71.  
  72. gulp.task('normalize', function() {
  73. return gulp.src(src.normalize)
  74. .pipe(minifycss())
  75. .pipe(gulp.dest(dist.styles));
  76. })
  77.  
  78. gulp.task('styles', function() {
  79. return gulp.src(src.styles)
  80. //.pipe(sourcemaps.init())
  81. .pipe(minifycss({compatibility: 'ie8'}))
  82. .pipe(concat('styles.css'))
  83. .pipe(prefix({
  84. browsers: ['last 2 version'],
  85. cascade: false
  86. }))
  87. //.pipe(sourcemaps.write())
  88. .pipe(gulp.dest(dist.styles));
  89. });
  90.  
  91. gulp.task('images', function() {
  92. return gulp.src(src.images)
  93. .pipe(imagemin({
  94. optimizationLevel: 5,
  95. progressive: true,
  96. interlaced: true,
  97. multipass: true,
  98. svgoPlugins: [{removeViewBox: false}],
  99. use: [pngquant()]
  100. }))
  101. .pipe(gulp.dest(dist.images));
  102. });
  103.  
  104. gulp.task('fav', function() {
  105. return gulp.src(src.fav)
  106. .pipe(imagemin({
  107. optimizationLevel: 5,
  108. use: [pngquant()]
  109. }))
  110. .pipe(gulp.dest(dist.root));
  111. });
  112.  
  113. gulp.task('other', function() {
  114. return gulp.src(src.other)
  115. .pipe(gulp.dest(dist.root));
  116. });
  117.  
  118. gulp.task('markup-watch', ['markup'], sync.reload);
  119. gulp.task('scripts-watch', ['scripts'], sync.reload);
  120. gulp.task('styles-watch', ['styles'], sync.reload);
  121. gulp.task('images-watch', ['images'], sync.reload);
  122. gulp.task('fav-watch', ['fav'], sync.reload);
  123. gulp.task('other-watch', ['other'], sync.reload);
  124.  
  125. gulp.task('build', ['clean', 'markup', 'modernizr', 'jquery', 'scripts', 'normalize', 'styles', 'images', 'fav', 'other']);
  126.  
  127. gulp.task('serve', ['build'], function() {
  128. sync.init({
  129. notify: false,
  130. port: 8080,
  131. server: {
  132. baseDir: dist.root
  133. }
  134. });
  135. /*
  136. gulp.watch(src.markup, ['markup-watch']);
  137. gulp.watch(src.scripts, ['scripts-watch']);
  138. gulp.watch(src.styles, ['styles-watch']);
  139. gulp.watch(src.images, ['images-watch']);
  140. gulp.watch(src.fav, ['fav-watch']);
  141. gulp.watch(src.other, ['other-watch']);
  142. */
  143. gulp.watch(src.markup).on('change', sync.reload);
  144. gulp.watch(src.scripts).on('change', sync.reload);
  145. gulp.watch(src.styles).on('change', sync.reload);
  146. gulp.watch(src.images).on('change', sync.reload);
  147. gulp.watch(src.fav).on('change', sync.reload);
  148. gulp.watch(src.other).on('change', sync.reload);
  149. });
  150.  
  151. gulp.task('default', ['serve']);
Advertisement
Add Comment
Please, Sign In to add comment