gulpfile.js.back 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. var gulp = require('gulp');
  3. var gulpif = require('gulp-if');
  4. var sass = require('gulp-sass');
  5. var watch = require('gulp-watch');
  6. var autoprefixer = require('gulp-autoprefixer');
  7. var jsmin = require('gulp-jsmin');
  8. var stripDebug = require('gulp-strip-debug');
  9. var cssmin = require('gulp-cssmin');
  10. var rename = require('gulp-rename');
  11. // var mainBowerFiles = require('main-bower-files');
  12. var svgmin = require('gulp-svgmin');
  13. // to get minified assets run `gulp --env=prod`
  14. var argv = require('minimist')(process.argv.slice(2));
  15. console.dir(argv);
  16. var prod = argv.env == 'prod' ? true : false;
  17. function handleError(err) {
  18. console.log(err.toString());
  19. }
  20. gulp.task('scripts', gulp.series(function (done) {
  21. gulp.src(['./assets/scripts/main.js'])
  22. // .pipe(concat('main.js'))
  23. .pipe(gulpif(prod, stripDebug()))
  24. .pipe(gulpif(prod, jsmin()))
  25. .pipe(rename({suffix: '.min'}))
  26. .pipe(gulp.dest('./assets/dist/scripts/'));
  27. done();
  28. }));
  29. gulp.task('styles', gulp.series(function (done) {
  30. gulp.src(['./assets/styles/app.scss'])
  31. .pipe(sass().on('error', sass.logError))
  32. .pipe(autoprefixer({
  33. browsers: ['last 2 versions'],
  34. cascade: false
  35. })).on('error', handleError)
  36. // .pipe(prod ? cssmin() : util.noop())
  37. .pipe(gulpif(prod, cssmin()))
  38. // .pipe(cssmin())
  39. .pipe(rename({suffix: '.min'}))
  40. .pipe(gulp.dest('./assets/dist/styles/'));
  41. done();
  42. }));
  43. // gulp.task('bower', function() {
  44. // gulp.src(mainBowerFiles({
  45. // "overrides":{
  46. // "masonry-layout":{
  47. // "main":"./dist/masonry.pkgd.min.js"
  48. // },
  49. // "imagesloaded":{
  50. // "main":"./imagesloaded.pkgd.min.js"
  51. // },
  52. // "jquery":{"ignore":true},
  53. // "ev-emitter":{"ignore":true},
  54. // "fizzy-ui-utils":{"ignore":true},
  55. // "get-size":{"ignore":true},
  56. // "outlayer":{"ignore":true},
  57. // }
  58. // }))
  59. // .pipe(gulp.dest('./assets/dist/bower/'));
  60. // });
  61. gulp.task('svg', gulp.series(function (done) {
  62. gulp.src(['./assets/img/*.svg'])
  63. .pipe(svgmin())
  64. .pipe(gulp.dest('./assets/dist/img'));
  65. done();
  66. }));
  67. // default gulp task
  68. //'bower',
  69. gulp.task('default', gulp.series(['scripts', 'styles', 'svg'], function(done) {
  70. gulp.watch('./assets/styles/*.scss', gulp.series('styles'));
  71. gulp.watch('./assets/styles/base/*.scss', gulp.series('styles'));
  72. gulp.watch('./assets/scripts/*.js', gulp.series('scripts'));
  73. gulp.watch('./assets/img/*.svg', gulp.series('svg'));
  74. done();
  75. }));