gulpfile.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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', done => {
  27. gulp.src(['./assets/scripts/main.js', './assets/scripts/redirect.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. done()
  34. });
  35. gulp.task('styles', done => {
  36. gulp.src(['./assets/styles/app.scss'])
  37. .pipe(sass().on('error', sass.logError))
  38. .pipe(autoprefixer({
  39. browsers: ['last 2 versions'],
  40. cascade: false
  41. })).on('error', handleError)
  42. // .pipe(prod ? cssmin() : util.noop())
  43. .pipe(gulpif(prod, cssmin()))
  44. // .pipe(cssmin())
  45. .pipe(rename({suffix: '.min'}))
  46. .pipe(gulp.dest('./assets/dist/styles/'));
  47. done()
  48. });
  49. gulp.task('bower', done => {
  50. gulp.src(mainBowerFiles({
  51. "overrides":{
  52. "masonry-layout":{
  53. "main":"./dist/masonry.pkgd.min.js"
  54. },
  55. "imagesloaded":{
  56. "main":"./imagesloaded.pkgd.min.js"
  57. },
  58. "jquery":{"ignore":true},
  59. "ev-emitter":{"ignore":true},
  60. "fizzy-ui-utils":{"ignore":true},
  61. "get-size":{"ignore":true},
  62. "outlayer":{"ignore":true},
  63. }
  64. }))
  65. .pipe(gulp.dest('./assets/dist/bower/'));
  66. done()
  67. });
  68. gulp.task('svg', done => {
  69. gulp.src(['./assets/img/*.svg', '!./assets/img/edlp-loader-anim.svg'])
  70. .pipe(svgmin())
  71. .pipe(gulp.dest('./assets/dist/img'));
  72. gulp.src('./assets/img/edlp-loader-anim.svg')
  73. .pipe(gulp.dest('./assets/dist/img'));
  74. done()
  75. });
  76. // default gulp task
  77. // , 'vars2sass' 'vars2js',
  78. // gulp.task('default', ['bower', 'scripts', 'styles', 'svg'], function() {
  79. gulp.task('default', gulp.series('bower', 'scripts', 'styles', 'svg', function(done) {
  80. // gulp.watch('./assets/json/*.json', ['vars2js', 'styles', 'scripts']); //, 'vars2sass'
  81. gulp.watch('./assets/styles/*.scss', gulp.series('styles'));
  82. gulp.watch('./assets/styles/base/*.scss', gulp.series('styles'));
  83. gulp.watch('./assets/scripts/*.js', gulp.series('scripts'));
  84. gulp.watch('./assets/img/*.svg', gulp.series('svg'));
  85. done()
  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. // });