You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 line
1.4 KiB

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