gulpTasks-watchLibraries.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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("watchLibraries", function startWatch() {
  14. var tasks = [];
  15. config.modules.map(function(module) {
  16. var settings = config[module].build;
  17. if (!config[module].isCore && settings && settings.webpack) {
  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. let wpConfig = require(settings.webpack);
  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. var rootPath = path.resolve(__dirname, "../../../");
  30. var absoluteSrc = path.resolve(__dirname, "../", settings.srcDirectory);
  31. wpConfig.output.devtoolModuleFilenameTemplate = (info) => {
  32. info.resourcePath = path.normalize(info.resourcePath);
  33. if (!path.isAbsolute(info.resourcePath)) {
  34. info.resourcePath = path.join(absoluteSrc, info.resourcePath);
  35. }
  36. return `"../../${path.relative(rootPath, info.resourcePath).replace(/\\/g, "/")}`;
  37. };
  38. tasks.push(
  39. gulp.src(settings.srcDirectory + "**/*.fx")
  40. .pipe(uncommentShaders())
  41. .pipe(processShaders(false))
  42. );
  43. var outputDirectory = config.build.tempDirectory + settings.distOutputDirectory;
  44. tasks.push(
  45. webpackStream(wpConfig, webpack).pipe(gulp.dest(outputDirectory))
  46. );
  47. tasks.push(
  48. gulp.watch(settings.srcDirectory + "**/*.fx", { interval: 1000 }, function() {
  49. console.log(library.output + ": Shaders.");
  50. return gulp.src(settings.srcDirectory + "**/*.fx")
  51. .pipe(uncommentShaders())
  52. .pipe(processShaders(false));
  53. })
  54. );
  55. }
  56. }
  57. });
  58. return Promise.resolve();
  59. });