gulpTasks-watchLibraries.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Import Dependencies.
  2. var gulp = require("gulp");
  3. var webpack = require('webpack');
  4. var webpackStream = require("webpack-stream");
  5. var path = require("path");
  6. var processShaders = require("../helpers/gulp-processShaders");
  7. var uncommentShaders = require('../helpers/gulp-removeShaderComments');
  8. // Read the full config.
  9. var config = require("../../Config/config.js");
  10. /**
  11. * Watch ts files and fire repective tasks.
  12. */
  13. gulp.task("watchLibraries", function startWatch() {
  14. var tasks = [];
  15. config.modules.map(function(module) {
  16. var settings = config[module].computed;
  17. if (!config[module].isCore && settings) {
  18. for (var index = 0; index < config[module].libraries.length; index++) {
  19. var library = config[module].libraries[index];
  20. if (library.preventLoadLibrary) {
  21. continue;
  22. }
  23. var wpConfig = require(settings.webpackConfigPath);
  24. // watch on.
  25. wpConfig.watch = true;
  26. // dev mode and absolute path sourcemaps for debugging
  27. wpConfig.mode = "development";
  28. wpConfig.devtool = "nosources-source-map";
  29. // Source Map Remapping for dev tools.
  30. wpConfig.output.devtoolModuleFilenameTemplate = (info) => {
  31. info.resourcePath = path.normalize(info.resourcePath);
  32. if (!path.isAbsolute(info.resourcePath)) {
  33. info.resourcePath = path.join(settings.srcDirectory, info.resourcePath);
  34. }
  35. return `../../../${path.relative(config.computed.rootFolder, info.resourcePath).replace(/\\/g, "/")}`;
  36. };
  37. tasks.push(
  38. gulp.src(settings.shaderGlob)
  39. .pipe(uncommentShaders())
  40. .pipe(processShaders(false))
  41. );
  42. var outputDirectory = settings.localDevUMDDirectory;
  43. tasks.push(
  44. webpackStream(wpConfig, webpack)
  45. .pipe(gulp.dest(outputDirectory))
  46. );
  47. var watch = gulp.watch(settings.shaderGlob, { interval: 1000 }, function() {
  48. console.log(library.output + ": Shaders.");
  49. })
  50. watch.on("add", (event) => {
  51. return gulp.src(event)
  52. .pipe(uncommentShaders())
  53. .pipe(processShaders(false));
  54. });
  55. watch.on("change", (event) => {
  56. return gulp.src(event)
  57. .pipe(uncommentShaders())
  58. .pipe(processShaders(false));
  59. });
  60. tasks.push(watch);
  61. }
  62. }
  63. });
  64. return Promise.resolve();
  65. });