Skip to content

Commit 073cb55

Browse files
djgrantTimer
authored andcommitted
Move dev server config into config file
1 parent 6bd6381 commit 073cb55

File tree

3 files changed

+52
-54
lines changed

3 files changed

+52
-54
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var config = require('./webpack.config.dev');
2+
var paths = require('./paths');
3+
4+
var protocol = process.env.HTTPS === 'true' ? "https" : "http";
5+
var host = process.env.HOST || 'localhost';
6+
7+
module.exports = {
8+
// Enable gzip compression of generated files.
9+
compress: true,
10+
// Silence WebpackDevServer's own logs since they're generally not useful.
11+
// It will still show compile warnings and errors with this setting.
12+
clientLogLevel: 'none',
13+
// By default WebpackDevServer serves physical files from current directory
14+
// in addition to all the virtual build products that it serves from memory.
15+
// This is confusing because those files won’t automatically be available in
16+
// production build folder unless we copy them. However, copying the whole
17+
// project directory is dangerous because we may expose sensitive files.
18+
// Instead, we establish a convention that only files in `public` directory
19+
// get served. Our build script will copy `public` into the `build` folder.
20+
// In `index.html`, you can get URL of `public` folder with %PUBLIC_PATH%:
21+
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
22+
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
23+
// Note that we only recommend to use `public` folder as an escape hatch
24+
// for files like `favicon.ico`, `manifest.json`, and libraries that are
25+
// for some reason broken when imported through Webpack. If you just want to
26+
// use an image, put it in `src` and `import` it from JavaScript instead.
27+
contentBase: paths.appPublic,
28+
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
29+
// for the WebpackDevServer client so it can learn when the files were
30+
// updated. The WebpackDevServer client is included as an entry point
31+
// in the Webpack development configuration. Note that only changes
32+
// to CSS are currently hot reloaded. JS changes will refresh the browser.
33+
hot: true,
34+
// It is important to tell WebpackDevServer to use the same "root" path
35+
// as we specified in the config. In development, we always serve from /.
36+
publicPath: config.output.publicPath,
37+
// WebpackDevServer is noisy by default so we emit custom message instead
38+
// by listening to the compiler events with `compiler.plugin` calls above.
39+
quiet: true,
40+
// Reportedly, this avoids CPU overload on some systems.
41+
// https://github.com/facebookincubator/create-react-app/issues/293
42+
watchOptions: {
43+
ignored: /node_modules/
44+
},
45+
// Enable HTTPS if the HTTPS environment variable is set to 'true'
46+
https: protocol === "https",
47+
host: host
48+
};

packages/react-scripts/scripts/start.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ require('dotenv').config({silent: true});
2020
var fs = require('fs');
2121
var chalk = require('chalk');
2222
var detect = require('detect-port');
23+
var WebpackDevServer = require('webpack-dev-server');
2324
var clearConsole = require('react-dev-utils/clearConsole');
2425
var checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
2526
var getProcessForPort = require('react-dev-utils/getProcessForPort');
2627
var openBrowser = require('react-dev-utils/openBrowser');
2728
var prompt = require('react-dev-utils/prompt');
2829
var paths = require('../config/paths');
2930
var config = require('../config/webpack.config.dev');
31+
var devServerConfig = require('../config/webpackDevServer.config');
3032
var createWebpackCompiler = require('../utils/createWebpackCompiler');
31-
var createWebpackDevServer = require('../utils/createWebpackDevServer');
3233
var addWebpackMiddleware = require('../utils/addWebpackMiddleware');
3334

3435
var useYarn = fs.existsSync(paths.yarnLockFile);
@@ -59,8 +60,8 @@ function run(port) {
5960
console.log();
6061
});
6162

62-
// Serve webpack assets generated by the compiler over http.
63-
var devServer = createWebpackDevServer(compiler, protocol, host);
63+
// Serve webpack assets generated by the compiler over a web sever.
64+
var devServer = new WebpackDevServer(compiler, devServerConfig);
6465

6566
// Our custom middleware proxies requests to /index.html or a remote API.
6667
addWebpackMiddleware(devServer);

packages/react-scripts/utils/createWebpackDevServer.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)