gulpTasks-watchApps.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Read the full config.
  7. var config = require("../../Config/config.js");
  8. /**
  9. * Watch ts files and fire repective tasks.
  10. */
  11. gulp.task("watchApps", function startWatch() {
  12. var tasks = [];
  13. config.apps.map(function(module) {
  14. // Convert Module to Namespace for globals
  15. var settings = config[module].computed;
  16. if (settings) {
  17. var wpConfig = require(settings.webpackConfigPath);
  18. // watch on.
  19. wpConfig.watch = true;
  20. // dev mode and absolute path sourcemaps for debugging
  21. wpConfig.mode = "development";
  22. wpConfig.devtool = "nosources-source-map";
  23. // Source Map Remapping for dev tools.
  24. wpConfig.output.devtoolModuleFilenameTemplate = (info) => {
  25. info.resourcePath = path.normalize(info.resourcePath);
  26. if (!path.isAbsolute(info.resourcePath)) {
  27. info.resourcePath = path.join(settings.srcDirectory, info.resourcePath);
  28. }
  29. return `../../../${path.relative(config.computed.rootFolder, info.resourcePath).replace(/\\/g, "/")}`;
  30. };
  31. var outputDirectory = settings.distDirectory;
  32. tasks.push(
  33. webpackStream(wpConfig , webpack)
  34. .pipe(gulp.dest(outputDirectory))
  35. );
  36. }
  37. });
  38. return Promise.resolve();
  39. });