gulpTasks-watchLibraries.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 configPath = "../config.json";
  10. var config = require(configPath);
  11. /**
  12. * Watch ts files and fire repective tasks.
  13. */
  14. gulp.task("watchLibraries", function startWatch() {
  15. var tasks = [];
  16. config.modules.map(function(module) {
  17. var settings = config[module].build;
  18. if (!config[module].isCore && 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. var configFolder = path.dirname(path.resolve(__dirname, configPath));
  25. var wpConfig = require(path.resolve(configFolder, settings.webpack));
  26. // watch on.
  27. wpConfig.watch = true;
  28. // dev mode and absolute path sourcemaps for debugging
  29. wpConfig.mode = "development";
  30. wpConfig.devtool = "nosources-source-map";
  31. var rootPath = path.resolve(__dirname, "../../../");
  32. var absoluteSrc = path.resolve(__dirname, "../", settings.srcDirectory);
  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 `../../../${path.relative(rootPath, info.resourcePath).replace(/\\/g, "/")}`;
  39. };
  40. tasks.push(
  41. gulp.src(settings.srcDirectory + "**/*.fx")
  42. .pipe(uncommentShaders())
  43. .pipe(processShaders(false))
  44. );
  45. var outputDirectory = config.build.tempDirectory + config.build.localDevUMDFolderName + 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(false));
  55. })
  56. );
  57. }
  58. }
  59. });
  60. return Promise.resolve();
  61. });