gulpfile.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 jsonToSass = require('gulp-json-to-sass');
  13. // var concat = require('gulp-concat');
  14. var svgmin = require('gulp-svgmin');
  15. // var fs = require('fs');
  16. // var json2js = require('gulp-json2js');
  17. // var data = require('gulp-data');
  18. // var shared_variables = JSON.parse(fs.readFileSync('./assets/json/shared_variables.json'));
  19. // to get minified assets run `gulp --env=prod`
  20. var argv = require('minimist')(process.argv.slice(2));
  21. console.dir(argv);
  22. var prod = argv.env == 'prod' ? true : false;
  23. function handleError(err) {
  24. console.log(err.toString());
  25. }
  26. gulp.task('scripts', function () {
  27. gulp.src(['./assets/scripts/main.js', './assets/scripts/history.js']) // './assets/scripts/shared_variables.js',
  28. // .pipe(concat('main.js'))
  29. .pipe(gulpif(prod, stripDebug()))
  30. .pipe(gulpif(prod, jsmin()))
  31. .pipe(rename({suffix: '.min'}))
  32. .pipe(gulp.dest('./assets/dist/scripts/'));
  33. });
  34. gulp.task('styles', function () {
  35. gulp.src(['./assets/styles/app.scss'])
  36. .pipe(sass().on('error', sass.logError))
  37. .pipe(autoprefixer({
  38. browsers: ['last 2 versions'],
  39. cascade: false
  40. })).on('error', handleError)
  41. // .pipe(prod ? cssmin() : util.noop())
  42. .pipe(gulpif(prod, cssmin()))
  43. // .pipe(cssmin())
  44. .pipe(rename({suffix: '.min'}))
  45. .pipe(gulp.dest('./assets/dist/styles/'));
  46. });
  47. gulp.task('bower', function() {
  48. gulp.src(mainBowerFiles({
  49. "overrides":{
  50. "masonry-layout":{
  51. "main":"./dist/masonry.pkgd.min.js"
  52. },
  53. "imagesloaded":{
  54. "main":"./imagesloaded.pkgd.min.js"
  55. },
  56. "jquery":{"ignore":true},
  57. "ev-emitter":{"ignore":true},
  58. "fizzy-ui-utils":{"ignore":true},
  59. "get-size":{"ignore":true},
  60. "outlayer":{"ignore":true},
  61. }
  62. }))
  63. .pipe(gulp.dest('./assets/dist/bower/'));
  64. });
  65. gulp.task('svg', function () {
  66. gulp.src(['./assets/img/*.svg', '!./assets/img/edlp-loader-anim.svg'])
  67. .pipe(svgmin())
  68. .pipe(gulp.dest('./assets/dist/img'));
  69. gulp.src('./assets/img/edlp-loader-anim.svg')
  70. .pipe(gulp.dest('./assets/dist/img'));
  71. });
  72. // default gulp task
  73. // , 'vars2sass' 'vars2js',
  74. gulp.task('default', ['bower', 'scripts', 'styles', 'svg'], function() {
  75. // gulp.watch('./assets/json/*.json', ['vars2js', 'styles', 'scripts']); //, 'vars2sass'
  76. gulp.watch('./assets/styles/*.scss', ['styles']);
  77. gulp.watch('./assets/styles/base/*.scss', ['styles']);
  78. gulp.watch('./assets/scripts/*.js', ['scripts']);
  79. gulp.watch('./assets/img/*.svg', ['svg']);
  80. });
  81. // this task stays here just for memeomry about how to share variables between js and css
  82. // gulp.task('vars2sass', function () {
  83. // gulp.src('./assets/json/shared_variables.json')
  84. // .pipe(jsonToSass({
  85. // jsonPath: './assets/json/shared_variables.json',
  86. // scssPath: './assets/styles/base/_shared_variables.scss'
  87. // }));
  88. // });
  89. // this one is not working, works first run but then it's like it's caching the source
  90. // gulp.task('variables2js', function() {
  91. // gulp.src('./assets/scripts/shared_variables_model.js')
  92. // .pipe(rename('shared_variables.js'))
  93. // .pipe(data(function(file) {
  94. // delete require.cache['./assets/json/shared_variables.json'];
  95. // return require('./assets/json/shared_variables.json');
  96. // }))
  97. // .pipe(json2js())
  98. // .pipe(gulp.dest('./assets/scripts/'));
  99. // });
  100. // gulp.task('vars2js', function() {
  101. // gulp.src('./assets/json/shared_variables.json')
  102. // .pipe(rename('shared_variables.js'))
  103. // .pipe(through.obj(function (file, enc, cb) {
  104. // // console.log('file',String(file.contents));
  105. // // small pipe to wrappe json data into a js variable
  106. // file.contents = new Buffer("edlp_vars = "+String(file.contents).trim()+";");
  107. // cb(null, file);
  108. // }))
  109. // .pipe(gulp.dest('./assets/scripts/'));
  110. // });