gulpfile.babel.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Available build configurations: 4 in case of modules connecting to API, otherwise only 2
  3. * - development - offline
  4. * - development - online
  5. * - production - offline
  6. * - production - online
  7. *
  8. * Distinction between development and production targets by environment variable process.env.NODE_ENV
  9. * Online / offline versions (API usage or locally defined data) by command line arguments (default: online)
  10. */
  11. import path from 'path';
  12. import config from './config';
  13. import gulp from 'gulp';
  14. import { clean } from './tasks/clean';
  15. import { html } from './tasks/html';
  16. import { sprites } from './tasks/sprites';
  17. import { copyFonts, copyImages } from './tasks/copy';
  18. import { lint, lintJs, lintSass, lintHtml } from './tasks/lint';
  19. import { styles } from './tasks/styles';
  20. import { scripts } from './tasks/scripts';
  21. import { reload, serve } from './tasks/server';
  22. // Delete previously built files, generate html and sprites
  23. const prepare = gulp.series(
  24. clean,
  25. html,
  26. sprites
  27. );
  28. // Copy assets
  29. const finish = gulp.parallel(
  30. copyFonts,
  31. copyImages
  32. );
  33. // Execute complete build process
  34. const build = gulp.series(
  35. prepare,
  36. gulp.parallel(lintSass, lintJs, lintHtml),
  37. gulp.parallel(styles, scripts),
  38. finish
  39. );
  40. // Watch files and react accordingly
  41. const watchFiles = () => {
  42. // HTML
  43. gulp.watch(
  44. path.join(
  45. config.paths.src,
  46. config.paths.html,
  47. '*.html'
  48. ),
  49. gulp.series(html, reload)
  50. );
  51. // Javascript
  52. gulp.watch(
  53. path.join(
  54. config.paths.src,
  55. config.paths.js,
  56. '/**/*.(js|jsx|json)'
  57. ),
  58. gulp.series(scripts, reload)
  59. );
  60. // Sass
  61. gulp.watch(
  62. path.join(
  63. config.paths.src,
  64. config.paths.sass,
  65. '/**/*.scss'
  66. ),
  67. gulp.series(styles, reload)
  68. );
  69. // Fonts
  70. gulp.watch(
  71. path.join(
  72. config.paths.src,
  73. config.paths.fonts,
  74. '*.(woff|woff2)'
  75. ),
  76. gulp.series(copyFonts, reload)
  77. );
  78. // Images
  79. gulp.watch(
  80. path.join(
  81. config.paths.src,
  82. config.paths.images,
  83. '*.(png|jpg)'
  84. ),
  85. gulp.series(copyImages, reload)
  86. );
  87. // Sprites
  88. gulp.watch(
  89. path.join(
  90. config.paths.src,
  91. config.paths.images,
  92. config.paths.sprites,
  93. '*.svg'
  94. ),
  95. gulp.series(sprites, copyImages, reload)
  96. );
  97. };
  98. // Build first, then serve and watch files
  99. const watch = gulp.series(
  100. build,
  101. serve,
  102. watchFiles
  103. );
  104. // hack-a-di-hack: export named default task as default
  105. // (which is a javascript keyword but at the same time the name
  106. // of the gulp default task. Very good, gulp. Or, maybe, rather not
  107. export {
  108. watch as default,
  109. build,
  110. lint,
  111. prepare,
  112. watch
  113. };