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

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // @remove-on-eject-begin
  2. /**
  3. * Copyright (c) 2015-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. // @remove-on-eject-end
  9. 'use strict';
  10. // Do this as the first thing so that any code reading it knows the right env.
  11. process.env.BABEL_ENV = 'development';
  12. process.env.NODE_ENV = 'development';
  13. // Makes the script crash on unhandled rejections instead of silently
  14. // ignoring them. In the future, promise rejections that are not handled will
  15. // terminate the Node.js process with a non-zero exit code.
  16. process.on('unhandledRejection', err => {
  17. throw err;
  18. });
  19. // Ensure environment variables are read.
  20. require('../config/env');
  21. // @remove-on-eject-begin
  22. // Do the preflight check (only happens before eject).
  23. const verifyPackageTree = require('./utils/verifyPackageTree');
  24. if (process.env.SKIP_PREFLIGHT_CHECK !== 'true') {
  25. verifyPackageTree();
  26. }
  27. const verifyTypeScriptSetup = require('./utils/verifyTypeScriptSetup');
  28. verifyTypeScriptSetup();
  29. // @remove-on-eject-end
  30. const fs = require('fs');
  31. const chalk = require('chalk');
  32. const webpack = require('webpack');
  33. const WebpackDevServer = require('webpack-dev-server');
  34. const clearConsole = require('react-dev-utils/clearConsole');
  35. const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
  36. const {
  37. choosePort,
  38. createCompiler,
  39. prepareProxy,
  40. prepareUrls,
  41. } = require('react-dev-utils/WebpackDevServerUtils');
  42. const openBrowser = require('react-dev-utils/openBrowser');
  43. const paths = require('../config/paths');
  44. const config = require('../config/webpack.config.dev');
  45. const createDevServerConfig = require('../config/webpackDevServer.config');
  46. const useYarn = fs.existsSync(paths.yarnLockFile);
  47. const isInteractive = process.stdout.isTTY;
  48. // Warn and crash if required files are missing
  49. if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
  50. process.exit(1);
  51. }
  52. // Tools like Cloud9 rely on this.
  53. const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
  54. const HOST = process.env.HOST || '0.0.0.0';
  55. if (process.env.HOST) {
  56. console.log(
  57. chalk.cyan(
  58. `Attempting to bind to HOST environment variable: ${chalk.yellow(
  59. chalk.bold(process.env.HOST)
  60. )}`
  61. )
  62. );
  63. console.log(
  64. `If this was unintentional, check that you haven't mistakenly set it in your shell.`
  65. );
  66. console.log(
  67. `Learn more here: ${chalk.yellow('http://bit.ly/CRA-advanced-config')}`
  68. );
  69. console.log();
  70. }
  71. // We require that you explictly set browsers and do not fall back to
  72. // browserslist defaults.
  73. const { checkBrowsers } = require('react-dev-utils/browsersHelper');
  74. checkBrowsers(paths.appPath, isInteractive)
  75. .then(() => {
  76. // We attempt to use the default port but if it is busy, we offer the user to
  77. // run on a different port. `choosePort()` Promise resolves to the next free port.
  78. return choosePort(HOST, DEFAULT_PORT);
  79. })
  80. .then(port => {
  81. if (port == null) {
  82. // We have not found a port.
  83. return;
  84. }
  85. const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
  86. const appName = require(paths.appPackageJson).name;
  87. const urls = prepareUrls(protocol, HOST, port);
  88. // Create a webpack compiler that is configured with custom messages.
  89. const compiler = createCompiler(webpack, config, appName, urls, useYarn);
  90. // Load proxy config
  91. const proxySetting = require(paths.appPackageJson).proxy;
  92. const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
  93. // Serve webpack assets generated by the compiler over a web server.
  94. const serverConfig = createDevServerConfig(
  95. proxyConfig,
  96. urls.lanUrlForConfig
  97. );
  98. const devServer = new WebpackDevServer(compiler, serverConfig);
  99. // Launch WebpackDevServer.
  100. devServer.listen(port, HOST, err => {
  101. if (err) {
  102. return console.log(err);
  103. }
  104. if (isInteractive) {
  105. clearConsole();
  106. }
  107. console.log(chalk.cyan('Starting the development server...\n'));
  108. openBrowser(urls.localUrlForBrowser);
  109. });
  110. ['SIGINT', 'SIGTERM'].forEach(function(sig) {
  111. process.on(sig, function() {
  112. devServer.close();
  113. process.exit();
  114. });
  115. });
  116. })
  117. .catch(err => {
  118. if (err && err.message) {
  119. console.log(err.message);
  120. }
  121. process.exit(1);
  122. });