1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
7 // Do this as the first thing so that any code reading it knows the right env.
8 process.env.BABEL_ENV = 'development';
9 process.env.NODE_ENV = 'development';
11 // Makes the script crash on unhandled rejections instead of silently
12 // ignoring them. In the future, promise rejections that are not handled will
13 // terminate the Node.js process with a non-zero exit code.
14 process.on('unhandledRejection', err => {
18 // Ensure environment variables are read.
19 require('../config/env');
21 const fs = require('fs');
22 const chalk = require('react-dev-utils/chalk');
23 const webpack = require('webpack');
24 const WebpackDevServer = require('webpack-dev-server');
25 const clearConsole = require('react-dev-utils/clearConsole');
26 const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
32 } = require('react-dev-utils/WebpackDevServerUtils');
33 const openBrowser = require('react-dev-utils/openBrowser');
34 const semver = require('semver');
35 const paths = require('../config/paths');
36 const configFactory = require('../config/webpack.config');
37 const createDevServerConfig = require('../config/webpackDevServer.config');
38 const getClientEnvironment = require('../config/env');
39 const react = require(require.resolve('react', { paths: [paths.appPath] }));
41 const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
42 const useYarn = fs.existsSync(paths.yarnLockFile);
43 const isInteractive = process.stdout.isTTY;
45 // Warn and crash if required files are missing
46 if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
50 // Tools like Cloud9 rely on this.
51 const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
52 const HOST = process.env.HOST || '0.0.0.0';
54 if (process.env.HOST) {
57 `Attempting to bind to HOST environment variable: ${chalk.yellow(
58 chalk.bold(process.env.HOST)
63 `If this was unintentional, check that you haven't mistakenly set it in your shell.`
66 `Learn more here: ${chalk.yellow('https://cra.link/advanced-config')}`
71 // We require that you explicitly set browsers and do not fall back to
72 // browserslist defaults.
73 const { checkBrowsers } = require('react-dev-utils/browsersHelper');
74 checkBrowsers(paths.appPath, isInteractive)
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);
82 // We have not found a port.
86 const config = configFactory('development');
87 const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
88 const appName = require(paths.appPackageJson).name;
90 const useTypeScript = fs.existsSync(paths.appTsConfig);
91 const urls = prepareUrls(
95 paths.publicUrlOrPath.slice(0, -1)
97 // Create a webpack compiler that is configured with custom messages.
98 const compiler = createCompiler({
107 const proxySetting = require(paths.appPackageJson).proxy;
108 const proxyConfig = prepareProxy(
111 paths.publicUrlOrPath
113 // Serve webpack assets generated by the compiler over a web server.
114 const serverConfig = {
115 ...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
119 const devServer = new WebpackDevServer(serverConfig, compiler);
120 // Launch WebpackDevServer.
121 devServer.startCallback(() => {
126 if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
129 `Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
134 console.log(chalk.cyan('Starting the development server...\n'));
135 openBrowser(urls.localUrlForBrowser);
138 ['SIGINT', 'SIGTERM'].forEach(function (sig) {
139 process.on(sig, function () {
145 if (process.env.CI !== 'true') {
146 // Gracefully exit when stdin ends
147 process.stdin.on('end', function () {
154 if (err && err.message) {
155 console.log(err.message);