3// Do this as the first thing so that any code reading it knows the right env.
4process.env.BABEL_ENV = 'development';
5process.env.NODE_ENV = 'development';
7// Makes the script crash on unhandled rejections instead of silently
8// ignoring them. In the future, promise rejections that are not handled will
9// terminate the Node.js process with a non-zero exit code.
10process.on('unhandledRejection', err => {
14// Ensure environment variables are read.
15require('../config/env');
18const fs = require('fs');
19const chalk = require('react-dev-utils/chalk');
20const webpack = require('webpack');
21const WebpackDevServer = require('webpack-dev-server');
22const clearConsole = require('react-dev-utils/clearConsole');
23const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
29} = require('react-dev-utils/WebpackDevServerUtils');
30const openBrowser = require('react-dev-utils/openBrowser');
31const paths = require('../config/paths');
32const configFactory = require('../config/webpack.config');
33const createDevServerConfig = require('../config/webpackDevServer.config');
35const useYarn = fs.existsSync(paths.yarnLockFile);
36const isInteractive = process.stdout.isTTY;
38// Warn and crash if required files are missing
39if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
43// Tools like Cloud9 rely on this.
44const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
45const HOST = process.env.HOST || '0.0.0.0';
47if (process.env.HOST) {
50 `Attempting to bind to HOST environment variable: ${chalk.yellow(
51 chalk.bold(process.env.HOST)
56 `If this was unintentional, check that you haven't mistakenly set it in your shell.`
59 `Learn more here: ${chalk.yellow('https://bit.ly/CRA-advanced-config')}`
64// We require that you explicitly set browsers and do not fall back to
65// browserslist defaults.
66const { checkBrowsers } = require('react-dev-utils/browsersHelper');
67checkBrowsers(paths.appPath, isInteractive)
69 // We attempt to use the default port but if it is busy, we offer the user to
70 // run on a different port. `choosePort()` Promise resolves to the next free port.
71 return choosePort(HOST, DEFAULT_PORT);
75 // We have not found a port.
78 const config = configFactory('development');
79 const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
80 const appName = require(paths.appPackageJson).name;
81 const useTypeScript = fs.existsSync(paths.appTsConfig);
82 const urls = prepareUrls(protocol, HOST, port);
85 devServer.sockWrite(devServer.sockets, 'warnings', warnings),
87 devServer.sockWrite(devServer.sockets, 'errors', errors),
89 // Create a webpack compiler that is configured with custom messages.
90 const compiler = createCompiler({
100 const proxySetting = require(paths.appPackageJson).proxy;
101 const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
102 // Serve webpack assets generated by the compiler over a web server.
103 const serverConfig = createDevServerConfig(
107 const devServer = new WebpackDevServer(compiler, serverConfig);
108 // Launch WebpackDevServer.
109 devServer.listen(port, HOST, err => {
111 return console.log(err);
117 // We used to support resolving modules according to `NODE_PATH`.
118 // This now has been deprecated in favor of jsconfig/tsconfig.json
119 // This lets you use absolute paths in imports inside large monorepos:
120 if (process.env.NODE_PATH) {
123 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.'
129 console.log(chalk.cyan('Starting the development server...\n'));
130 openBrowser(urls.localUrlForBrowser);
133 ['SIGINT', 'SIGTERM'].forEach(function(sig) {
134 process.on(sig, function() {
141 if (err && err.message) {
142 console.log(err.message);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list