Skip to content

Commit ba47974

Browse files
committed
fix: 修复当入口为字符串类型时 hot-reload 不生效
1 parent 1072afe commit ba47974

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/commands/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,22 @@ exports.run = function (options) {
272272
if (!usingHotServer) {
273273
usingHotServer = projectName;
274274
if ((0, _typeof3.default)(wpConfig.entry) === 'object') {
275+
// 入口统一改成数组类型
276+
(0, _keys2.default)(wpConfig.entry).forEach(function (key) {
277+
if (typeof wpConfig.entry[key] === 'string') {
278+
wpConfig.entry[key] = [wpConfig.entry[key]];
279+
}
280+
});
281+
275282
(0, _keys2.default)(wpConfig.entry).map(function (key) {
276283
var entryItem = wpConfig.entry[key];
284+
277285
if (sysPath.extname(entryItem[entryItem.length - 1]) === '.js') {
278286
var whmPath = require.resolve('webpack-hot-middleware/client');
279287
var hotPath = 'http://127.0.0.1:' + port + '/__webpack_hmr';
280288
entryItem.unshift(whmPath + '?reload=true&path=' + hotPath + '&timeout=9999999&overlay=false');
281289
}
290+
282291
return entryItem;
283292
});
284293
}

src/commands/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,22 @@ exports.run = (options) => {
256256
if(!usingHotServer) {
257257
usingHotServer = projectName;
258258
if(typeof wpConfig.entry === 'object') {
259+
// 入口统一改成数组类型
260+
Object.keys(wpConfig.entry).forEach((key) => {
261+
if(typeof wpConfig.entry[key] === 'string') {
262+
wpConfig.entry[key] = [wpConfig.entry[key]];
263+
}
264+
});
265+
259266
Object.keys(wpConfig.entry).map((key) => {
260267
let entryItem = wpConfig.entry[key];
268+
261269
if(sysPath.extname(entryItem[entryItem.length - 1]) === '.js') {
262270
const whmPath = require.resolve('webpack-hot-middleware/client');
263271
const hotPath = `http://127.0.0.1:${port}/__webpack_hmr`;
264272
entryItem.unshift(whmPath + '?reload=true&path=' + hotPath + '&timeout=9999999&overlay=false');
265273
}
274+
266275
return entryItem;
267276
});
268277
}

0 commit comments

Comments
 (0)