gulpfile.js 4.2 KB

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