addDevServerEntrypoints.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. /* eslint no-param-reassign: 'off' */
  3. const createDomain = require('./createDomain');
  4. module.exports = function addDevServerEntrypoints(webpackOptions, devServerOptions, listeningApp) {
  5. if (devServerOptions.inline !== false) {
  6. // we're stubbing the app in this method as it's static and doesn't require
  7. // a listeningApp to be supplied. createDomain requires an app with the
  8. // address() signature.
  9. const app = listeningApp || {
  10. address() {
  11. return { port: devServerOptions.port };
  12. }
  13. };
  14. const domain = createDomain(devServerOptions, app);
  15. const devClient = [`${require.resolve('../../client/')}?${domain}`];
  16. if (devServerOptions.hotOnly) {
  17. devClient.push(require.resolve('webpack/hot/only-dev-server'));
  18. } else if (devServerOptions.hot) {
  19. devClient.push(require.resolve('webpack/hot/dev-server'));
  20. }
  21. const prependDevClient = (entry) => {
  22. if (typeof entry === 'function') {
  23. return () => Promise.resolve(entry()).then(prependDevClient);
  24. }
  25. if (typeof entry === 'object' && !Array.isArray(entry)) {
  26. const entryClone = {};
  27. Object.keys(entry).forEach((key) => {
  28. entryClone[key] = devClient.concat(entry[key]);
  29. });
  30. return entryClone;
  31. }
  32. return devClient.concat(entry);
  33. };
  34. [].concat(webpackOptions).forEach((wpOpt) => {
  35. wpOpt.entry = prependDevClient(wpOpt.entry || './src');
  36. });
  37. }
  38. };