gulpTasks-watch.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.json");
  10. /**
  11. * Watch ts files and fire repective tasks.
  12. */
  13. gulp.task("watch", function startWatch() {
  14. var tasks = [];
  15. config.modules.map(function(module) {
  16. var settings = config[module].build;
  17. var isCore = config[module].isCore;
  18. if (settings && settings.webpack) {
  19. for (var index = 0; index < config[module].libraries.length; index++) {
  20. var library = config[module].libraries[index];
  21. if (library.preventLoadLibrary) {
  22. continue;
  23. }
  24. let wpConfig = require(settings.webpack);
  25. // watch on.
  26. wpConfig.watch = true;
  27. // dev mode and absolute path sourcemaps for debugging
  28. wpConfig.mode = "development";
  29. wpConfig.devtool = "nosources-source-map";
  30. var rootPath = path.resolve(__dirname, "../../../");
  31. var absoluteSrc = path.resolve(__dirname, "../", settings.srcDirectory);
  32. var prefix = isCore ? "../" : "../../";
  33. wpConfig.output.devtoolModuleFilenameTemplate = (info) => {
  34. info.resourcePath = path.normalize(info.resourcePath);
  35. if (!path.isAbsolute(info.resourcePath)) {
  36. info.resourcePath = path.join(absoluteSrc, info.resourcePath);
  37. }
  38. return `${prefix}${path.relative(rootPath, info.resourcePath).replace(/\\/g, "/")}`;
  39. };
  40. tasks.push(
  41. gulp.src(settings.srcDirectory + "**/*.fx")
  42. .pipe(uncommentShaders())
  43. .pipe(processShaders(isCore))
  44. );
  45. var outputDirectory = config.build.tempDirectory + settings.distOutputDirectory;
  46. tasks.push(
  47. webpackStream(wpConfig, webpack).pipe(gulp.dest(outputDirectory))
  48. );
  49. tasks.push(
  50. gulp.watch(settings.srcDirectory + "**/*.fx", { interval: 1000 }, function() {
  51. console.log(library.output + ": Shaders.");
  52. return gulp.src(settings.srcDirectory + "**/*.fx")
  53. .pipe(uncommentShaders())
  54. .pipe(processShaders(isCore));
  55. })
  56. );
  57. }
  58. }
  59. });
  60. return Promise.resolve();
  61. });