Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. 'use strict';
  2. /* eslint-disable
  3. no-shadow,
  4. global-require,
  5. multiline-ternary,
  6. array-bracket-spacing,
  7. space-before-function-paren
  8. */
  9. const open = require('opn');
  10. const colors = {
  11. info (useColor, msg) {
  12. if (useColor) {
  13. // Make text blue and bold, so it *pops*
  14. return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`;
  15. }
  16. return msg;
  17. },
  18. error (useColor, msg) {
  19. if (useColor) {
  20. // Make text red and bold, so it *pops*
  21. return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`;
  22. }
  23. return msg;
  24. }
  25. };
  26. // eslint-disable-next-line
  27. const defaultTo = (value, def) => {
  28. return value == null ? def : value;
  29. };
  30. function version () {
  31. return `webpack-dev-server ${require('../package.json').version}\n` +
  32. `webpack ${require('webpack/package.json').version}`;
  33. }
  34. function status (uri, options, log, useColor) {
  35. const contentBase = Array.isArray(options.contentBase)
  36. ? options.contentBase.join(', ')
  37. : options.contentBase;
  38. if (options.socket) {
  39. log.info(`Listening to socket at ${colors.info(useColor, options.socket)}`);
  40. } else {
  41. log.info(`Project is running at ${colors.info(useColor, uri)}`);
  42. }
  43. log.info(
  44. `webpack output is served from ${colors.info(useColor, options.publicPath)}`
  45. );
  46. if (contentBase) {
  47. log.info(
  48. `Content not from webpack is served from ${colors.info(useColor, contentBase)}`
  49. );
  50. }
  51. if (options.historyApiFallback) {
  52. log.info(
  53. `404s will fallback to ${colors.info(useColor, options.historyApiFallback.index || '/index.html')}`
  54. );
  55. }
  56. if (options.bonjour) {
  57. log.info(
  58. 'Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'
  59. );
  60. }
  61. if (options.open) {
  62. let openOptions = {};
  63. let openMessage = 'Unable to open browser';
  64. if (typeof options.open === 'string') {
  65. openOptions = { app: options.open };
  66. openMessage += `: ${options.open}`;
  67. }
  68. open(uri + (options.openPage || ''), openOptions).catch(() => {
  69. log.warn(
  70. `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
  71. );
  72. });
  73. }
  74. }
  75. function bonjour (options) {
  76. const bonjour = require('bonjour')();
  77. bonjour.publish({
  78. name: 'Webpack Dev Server',
  79. port: options.port,
  80. type: 'http',
  81. subtypes: [ 'webpack' ]
  82. });
  83. process.on('exit', () => {
  84. bonjour.unpublishAll(() => {
  85. bonjour.destroy();
  86. });
  87. });
  88. }
  89. module.exports = {
  90. status,
  91. colors,
  92. version,
  93. bonjour,
  94. defaultTo
  95. };