gulpfile.mjs 4.6 KB

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