Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const path = require("path");
const open = require("opn");
const fs = require("fs");
const net = require("net");
const url = require("url");
const portfinder = require("portfinder");
const addDevServerEntrypoints = require("../lib/util/addDevServerEntrypoints");
const createDomain = require("../lib/util/createDomain");

// Local version replaces global one
try {
Expand Down Expand Up @@ -327,33 +328,7 @@ function processOptions(wpOpt) {
}

function startDevServer(wpOpt, options) {
const protocol = options.https ? "https" : "http";

// the formatted domain (url without path) of the webpack server
const domain = options.public ? `${protocol}://${options.public}` : url.format({
protocol: protocol,
hostname: options.host,
port: options.socket ? 0 : options.port.toString()
});

if(options.inline !== false) {
const devClient = [`${require.resolve("../client/")}?${domain}`];

if(options.hotOnly)
devClient.push("webpack/hot/only-dev-server");
else if(options.hot)
devClient.push("webpack/hot/dev-server");

[].concat(wpOpt).forEach(function(wpOpt) {
if(typeof wpOpt.entry === "object" && !Array.isArray(wpOpt.entry)) {
Object.keys(wpOpt.entry).forEach(function(key) {
wpOpt.entry[key] = devClient.concat(wpOpt.entry[key]);
});
} else {
wpOpt.entry = devClient.concat(wpOpt.entry);
}
});
}
addDevServerEntrypoints(wpOpt, options);

let compiler;
try {
Expand All @@ -372,7 +347,7 @@ function startDevServer(wpOpt, options) {
}));
}

const uri = domain + (options.inline !== false || options.lazy === true ? "/" : "/webpack-dev-server/");
const uri = createDomain(options) + (options.inline !== false || options.lazy === true ? "/" : "/webpack-dev-server/");

let server;
try {
Expand Down
3 changes: 3 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,7 @@ Server.prototype.invalidate = function() {
if(this.middleware) this.middleware.invalidate();
}

// Export this logic, so that other implementations, like task-runners can use it
Server.addDevServerEntrypoints = require("./util/addDevServerEntrypoints");

module.exports = Server;
24 changes: 24 additions & 0 deletions lib/util/addDevServerEntrypoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";
const createDomain = require("./createDomain");

module.exports = function addDevServerEntrypoints(webpackOptions, devServerOptions) {
if(devServerOptions.inline !== false) {
const domain = createDomain(devServerOptions);
const devClient = [`${require.resolve("../../client/")}?${domain}`];

if(devServerOptions.hotOnly)
devClient.push("webpack/hot/only-dev-server");
else if(devServerOptions.hot)
devClient.push("webpack/hot/dev-server");

[].concat(webpackOptions).forEach(function(wpOpt) {
if(typeof wpOpt.entry === "object" && !Array.isArray(wpOpt.entry)) {
Object.keys(wpOpt.entry).forEach(function(key) {
wpOpt.entry[key] = devClient.concat(wpOpt.entry[key]);
});
} else {
wpOpt.entry = devClient.concat(wpOpt.entry);
}
});
}
};
13 changes: 13 additions & 0 deletions lib/util/createDomain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
const url = require("url");

module.exports = function createDomain(options) {
const protocol = options.https ? "https" : "http";

// the formatted domain (url without path) of the webpack server
return options.public ? `${protocol}://${options.public}` : url.format({
protocol: protocol,
hostname: options.host,
port: options.socket ? 0 : options.port.toString()
});
};