gulpfile.mjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 minimist from 'minimist';
  14. // var es = require('event-stream');
  15. var modules = ['edlp_corpus', 'edlp_studio', 'edlp_search'];
  16. // to get minified assets run `gulp --env=prod`
  17. var argv = minimist(process.argv.slice(2));
  18. console.dir(argv);
  19. var prod = argv.env == 'prod' ? true : false;
  20. function handleError(err) {
  21. console.log(err.toString());
  22. }
  23. function scripts() {
  24. return new Promise(function(resolve, reject) {
  25. modules.map(function(module) {
  26. src('./'+module+'/assets/scripts/*.js')
  27. .pipe(gulpif(prod, stripDebug()))
  28. .pipe(gulpif(prod, jsmin()))
  29. .pipe(rename({suffix: '.min'}))
  30. .pipe(gulp.dest('./'+module+'/assets/dist/scripts/'));
  31. });
  32. resolve();
  33. });
  34. };
  35. function styles() {
  36. return new Promise(function(resolve, reject) {
  37. modules.map(function(module) {
  38. src('./'+module+'/assets/styles/*.scss')
  39. .pipe(sass().on('error', sass.logError))
  40. .pipe(autoprefixer({
  41. cascade: false
  42. })).on('error', handleError)
  43. .pipe(gulpif(prod, cssmin()))
  44. // .pipe(cssmin())
  45. .pipe(rename({suffix: '.min'}))
  46. .pipe(gulp.dest('./'+module+'/assets/dist/styles/'));
  47. });
  48. resolve();
  49. });
  50. };
  51. // default gulp task
  52. function devwatch () {
  53. // series(scripts, styles, done => {
  54. for (var i = 0; i < modules.length; i++) {
  55. watch('./'+modules[i]+'/assets/styles/*.scss', styles);
  56. watch('./'+modules[i]+'/assets/scripts/*.js', scripts);
  57. }
  58. // done()
  59. // })
  60. };
  61. export default series(scripts, styles);
  62. export { devwatch }