gulpfile.mjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. var prod = true;
  22. function handleError(err) {
  23. console.log(err.toString());
  24. }
  25. async function scripts() {
  26. return src(['./assets/scripts/main.js', './assets/scripts/redirect.js']) // './assets/scripts/shared_variables.js',
  27. // .pipe(concat('main.js'))
  28. .pipe(gulpif(prod, stripDebug()))
  29. .pipe(gulpif(prod, jsmin()))
  30. .pipe(rename({suffix: '.min'}))
  31. .pipe(dest('./assets/dist/scripts/'));
  32. }
  33. async function styles() {
  34. return 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(prod ? cssmin() : util.noop())
  41. .pipe(gulpif(prod, cssmin()))
  42. // .pipe(cssmin())
  43. .pipe(rename({suffix: '.min'}))
  44. .pipe(gulp.dest('./assets/dist/styles/'));
  45. }
  46. async function bower(){
  47. return src(mainBowerFiles({
  48. "overrides":{
  49. "masonry-layout":{
  50. "main":"./dist/masonry.pkgd.min.js"
  51. },
  52. "imagesloaded":{
  53. "main":"./imagesloaded.pkgd.min.js"
  54. },
  55. "jquery":{"ignore":true},
  56. "ev-emitter":{"ignore":true},
  57. "fizzy-ui-utils":{"ignore":true},
  58. "get-size":{"ignore":true},
  59. "outlayer":{"ignore":true},
  60. }
  61. }))
  62. .pipe(gulp.dest('./assets/dist/bower/'));
  63. }
  64. async function minsvg(){
  65. return src(['./assets/img/*.svg', '!./assets/img/edlp-loader-anim.svg'])
  66. .pipe(svgmin())
  67. .pipe(gulp.dest('./assets/dist/img'));
  68. }
  69. async function svg(){
  70. return src('./assets/img/edlp-loader-anim.svg')
  71. .pipe(gulp.dest('./assets/dist/img'));
  72. }
  73. function devwatch(){
  74. watch('./assets/styles/*.scss', styles);
  75. watch('./assets/styles/base/*.scss', styles);
  76. watch('./assets/scripts/*.js', scripts);
  77. watch('./assets/img/*.svg', svg);
  78. }
  79. export default series(scripts, styles, svg, minsvg);
  80. export { devwatch }