gulpTasks-watchApps.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const moduleConfig = config[module];
  16. const pathDepth = moduleConfig.distFile.split('/').length - 2;
  17. let mapPathPrefix = "";
  18. for (let i = 0; i < pathDepth; i++) {
  19. mapPathPrefix += "../";
  20. }
  21. const settings = moduleConfig.computed;
  22. if (settings) {
  23. const 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 `${mapPathPrefix}${path.relative(config.computed.rootFolder, info.resourcePath).replace(/\\/g, "/")}`;
  36. };
  37. const outputDirectory = moduleConfig.tempFileName ? settings.localDevAppDirectory : settings.distDirectory;
  38. tasks.push(
  39. webpackStream(wpConfig , webpack)
  40. .pipe(gulp.dest(outputDirectory))
  41. );
  42. }
  43. });
  44. return Promise.resolve();
  45. });