Skip to content

Commit f7e922d

Browse files
fix: do not inject client when hot and livereload disabled (#3431)
1 parent 9264812 commit f7e922d

33 files changed

+4461
-1745
lines changed

lib/Server.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class Server {
718718
this.options.port,
719719
this.options.host,
720720
(error) => {
721-
if (this.options.hot || this.options.liveReload) {
721+
if (Boolean(this.options.hot) || this.options.liveReload) {
722722
this.createWebSocketServer();
723723
}
724724

@@ -936,26 +936,28 @@ class Server {
936936
}
937937

938938
serveMagicHtml(req, res, next) {
939-
const _path = req.path;
939+
this.middleware.waitUntilValid(() => {
940+
const _path = req.path;
940941

941-
try {
942-
const filename = this.middleware.getFilenameFromUrl(`${_path}.js`);
943-
const isFile = this.middleware.context.outputFileSystem
944-
.statSync(filename)
945-
.isFile();
942+
try {
943+
const filename = this.middleware.getFilenameFromUrl(`${_path}.js`);
944+
const isFile = this.middleware.context.outputFileSystem
945+
.statSync(filename)
946+
.isFile();
946947

947-
if (!isFile) {
948-
return next();
949-
}
948+
if (!isFile) {
949+
return next();
950+
}
950951

951-
// Serve a page that executes the javascript
952-
const queries = req._parsedUrl.search || '';
953-
const responsePage = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script type="text/javascript" charset="utf-8" src="${_path}.js${queries}"></script></body></html>`;
952+
// Serve a page that executes the javascript
953+
const queries = req._parsedUrl.search || '';
954+
const responsePage = `<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script type="text/javascript" charset="utf-8" src="${_path}.js${queries}"></script></body></html>`;
954955

955-
res.send(responsePage);
956-
} catch (error) {
957-
return next();
958-
}
956+
res.send(responsePage);
957+
} catch (error) {
958+
return next();
959+
}
960+
});
959961
}
960962

961963
// Send stats to a socket or multiple sockets

lib/utils/DevServerPlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ class DevServerPlugin {
214214
checkInject(
215215
this.options.client ? this.options.client.needClientEntry : null,
216216
compiler.options,
217-
this.isWebTarget(compiler.options)
217+
this.isWebTarget(compiler.options) &&
218+
(Boolean(this.options.hot) || this.options.liveReload)
218219
)
219220
) {
220221
additionalEntries.push(clientEntry);

0 commit comments

Comments
 (0)