Skip to content

Commit 0f16000

Browse files
committed
fix: 去掉 hot-reload 对于 publicPath 的修改
1 parent 2efb72b commit 0f16000

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

lib/commands/server.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,11 @@ exports.run = function (options) {
249249
// hot reload
250250
var hotEnabled = project.server && project.server.hot || hot;
251251
if (hotEnabled) {
252-
// 修改 publicPath 为当前服务
253252
var localPublicPath = wpConfig.output.local.publicPath;
254253
if (project.config.replacingPublicPath !== false) {
255254
var hostReg = /(http:|https:)?(\/\/)([^\/]+)/i;
256-
if (localPublicPath && localPublicPath.match(hostReg).length === 4) {
257-
localPublicPath = '/' + UtilPath.normalize(localPublicPath, false);
258-
localPublicPath = localPublicPath.replace(hostReg, function (matches, httpStr, splitStr, host) {
259-
httpStr = httpStr || '';
260-
return httpStr + '//' + '127.0.0.1:' + port;
261-
});
262-
wpConfig.output.local.publicPath = localPublicPath;
263-
} else {
255+
256+
if (!localPublicPath) {
264257
// hot 且 未指定 publicPath 需要手动设置方式 hot.json 404
265258
var relativePath = sysPath.relative(projectDir, wpConfig.output.local.path);
266259
wpConfig.output.local.publicPath = 'http://127.0.0.1:' + port + '/' + projectName + '/' + relativePath + '/';

src/commands/server.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,14 @@ exports.run = (options) => {
233233
// hot reload
234234
const hotEnabled = (project.server && project.server.hot) || hot;
235235
if(hotEnabled) {
236-
// 修改 publicPath 为当前服务
237-
let localPublicPath = wpConfig.output.local.publicPath;
238-
if(project.config.replacingPublicPath !== false) {
236+
const localPublicPath = wpConfig.output.local.publicPath;
237+
if (project.config.replacingPublicPath !== false) {
239238
const hostReg = /(http:|https:)?(\/\/)([^\/]+)/i;
240-
if(localPublicPath && localPublicPath.match(hostReg).length === 4) {
241-
localPublicPath = '/' + UtilPath.normalize(localPublicPath, false);
242-
localPublicPath = localPublicPath.replace(hostReg, (matches, httpStr, splitStr, host) => {
243-
httpStr = httpStr || '';
244-
return httpStr + '//' + '127.0.0.1:' + port;
245-
});
246-
wpConfig.output.local.publicPath = localPublicPath;
247-
} else {
239+
240+
if (!localPublicPath) {
248241
// hot 且 未指定 publicPath 需要手动设置方式 hot.json 404
249242
const relativePath = sysPath.relative(projectDir, wpConfig.output.local.path);
250-
wpConfig.output.local.publicPath = `http://127.0.0.1:${port}/${projectName}/${relativePath}/`;
243+
wpConfig.output.local.publicPath = 'http://127.0.0.1:' + port + '/' + projectName + '/' + relativePath + '/';
251244
}
252245
}
253246

0 commit comments

Comments
 (0)