Skip to content

Commit 3c1ff11

Browse files
shYkiStoSpaceK33z
authored andcommitted
Fix path to webpack client hot reload scripts to be resolved relatively (#1416)
* Fix path to webpack client hot reload scripts to be resolved relatively * Add tests for addDevServerEntrypoints hot/hotOnly branches
1 parent 33be88d commit 3c1ff11

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/util/addDevServerEntrypoints.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ module.exports = function addDevServerEntrypoints(webpackOptions, devServerOptio
1717
const domain = createDomain(devServerOptions, app);
1818
const devClient = [`${require.resolve('../../client/')}?${domain}`];
1919

20-
if (devServerOptions.hotOnly) { devClient.push('webpack/hot/only-dev-server'); } else if (devServerOptions.hot) { devClient.push('webpack/hot/dev-server'); }
20+
if (devServerOptions.hotOnly) {
21+
devClient.push(require.resolve('webpack/hot/only-dev-server'));
22+
} else if (devServerOptions.hot) {
23+
devClient.push(require.resolve('webpack/hot/dev-server'));
24+
}
2125

2226
const prependDevClient = (entry) => {
2327
if (typeof entry === 'function') {

test/Entry.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,38 @@ describe('Entry', () => {
110110
})
111111
)).catch(done);
112112
});
113+
114+
it('prepends webpack\'s hot reload client script', () => {
115+
const webpackOptions = Object.assign({}, config, {
116+
entry: {
117+
app: './app.js'
118+
}
119+
});
120+
const devServerOptions = {
121+
hot: true
122+
};
123+
124+
addDevServerEntrypoints(webpackOptions, devServerOptions);
125+
126+
const hotClientScript = webpackOptions.entry.app[1];
127+
assert.equal(hotClientScript.includes('webpack/hot/dev-server'), true);
128+
assert.equal(hotClientScript, require.resolve(hotClientScript));
129+
});
130+
131+
it('prepends webpack\'s hot-only client script', () => {
132+
const webpackOptions = Object.assign({}, config, {
133+
entry: {
134+
app: './app.js'
135+
}
136+
});
137+
const devServerOptions = {
138+
hotOnly: true
139+
};
140+
141+
addDevServerEntrypoints(webpackOptions, devServerOptions);
142+
143+
const hotClientScript = webpackOptions.entry.app[1];
144+
assert.equal(hotClientScript.includes('webpack/hot/only-dev-server'), true);
145+
assert.equal(hotClientScript, require.resolve(hotClientScript));
146+
});
113147
});

0 commit comments

Comments
 (0)